I just have tried out the Poco::URI class and it seems as if there is almost no syntax checking done?
I know that according to the RFC's Url and escpecially Uri are a very "loose" standard meaning that "almost anything" can be a Uri but if I remember right there must at least a scheme followed by a colon ?
I have tried several wrong Uri's/Urls's and only got a SyntaxException when I used a sigle ":" as an URI.
Does anybody know if the way Poco::URI handles syntax checking is wanted/ok ?
Here is the code I used for testing:
-----------------------------------------------------------------------------------------------
- Code: Select all
#include
#include
#include "Poco/URI.h"
#include "Poco/Exception.h"
int main(void)
{
std::string url1 = "http://stamper.tst.sub:8080/Otto/xmlrpc";
std::string url2 = "http_/stamper.tst.sub:8080/Otto/xmlrpc";
std::string url3 = "X-_21";
std::string url4 = "aaaa";
std::string url5 = "";
std::string url6 = "12345";
std::string url7 = "?????";
//std::string url7 = ":";
try
{
Poco::URI uri1( url1 );
Poco::URI uri2( url2 );
Poco::URI uri3( url3 );
Poco::URI uri4( url4 );
Poco::URI uri5( url5 );
Poco::URI uri6( url6 );
Poco::URI uri7( url7 );
std::cout << "uri1: scheme=" << uri1.getScheme()
<< " | host=" << uri1.getHost()
<< " | port=" << uri1.getPort()
<< " | path=" << uri1.getPath()
<< std::endl;
std::cout << "uri2: scheme=" << uri2.getScheme()
<< " | host=" << uri2.getHost()
<< " | port=" << uri2.getPort()
<< " | path=" << uri2.getPath()
<< std::endl;
std::cout << "uri3: scheme=" << uri3.getScheme()
<< " | host=" << uri3.getHost()
<< " | port=" << uri3.getPort()
<< " | path=" << uri3.getPath()
<< std::endl;
std::cout << "uri4: scheme=" << uri4.getScheme()
<< " | host=" << uri4.getHost()
<< " | port=" << uri4.getPort()
<< " | path=" << uri4.getPath()
<< std::endl;
std::cout << "uri5: scheme=" << uri5.getScheme()
<< " | host=" << uri5.getHost()
<< " | port=" << uri5.getPort()
<< " | path=" << uri5.getPath()
<< std::endl;
std::cout << "uri6: scheme=" << uri6.getScheme()
<< " | host=" << uri6.getHost()
<< " | port=" << uri6.getPort()
<< " | path=" << uri6.getPath()
<< std::endl;
std::cout << "uri7: scheme=" << uri7.getScheme()
<< " | host=" << uri7.getHost()
<< " | port=" << uri7.getPort()
<< " | path=" << uri7.getPath()
<< std::endl;
}
catch (const Poco::SyntaxException& e)
{
std::cout << e.displayText() << std::endl;
}
catch (const Poco::Exception& e)
{
std::cout << e.displayText() << std::endl;
}
catch (...)
{
std::cout << "Unknown exception" << std::endl;
}
return 0;
}
-----------------------------------------------------------------------------------------------
And here is the output:
-----------------------------------------------------------------------------------------------
- Code: Select all
uri1: scheme=http | host=stamper.tst.sub | port=8080 | path=/Otto/xmlrpc
uri2: scheme= | host= | port=0 | path=http_/stamper.tst.sub:8080/Otto/xmlrpc
uri3: scheme= | host= | port=0 | path=X-_21
uri4: scheme= | host= | port=0 | path=aaaa
uri5: scheme= | host= | port=0 | path=
uri6: scheme= | host= | port=0 | path=12345
uri7: scheme= | host= | port=0 | path=
-----------------------------------------------------------------------------------------------
regards,
Arno





