-
Notifications
You must be signed in to change notification settings - Fork 1.7k
added URI resolution according to RFC3986 #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
557b025
added URI resolution according to RFC3986, Section 5 (https://tools.i…
a34749c
fixed std::wstring -> utility::string_t
a218343
fixed literals
f78bc69
implemented suggestions by @BillyONeal;
f0d67cc
Make dotSegment and dotDotSegment global constants to pay for their c…
BillyONeal 7963710
Use push_back instead of initializer_list, minor whitespace fixups.
BillyONeal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "stdafx.h" | ||
|
||
using namespace web; | ||
using namespace utility; | ||
|
||
namespace tests { namespace functional { namespace uri_tests { | ||
|
||
//testing resolution against examples from Section 5.4 https://tools.ietf.org/html/rfc3986#section-5.4 | ||
SUITE(resolve_uri_tests) | ||
{ | ||
//5.4.1. Normal Examples https://tools.ietf.org/html/rfc3986#section-5.4.1 | ||
TEST(resolve_uri_normal) | ||
{ | ||
const uri baseUri = U("http://a/b/c/d;p?q"); | ||
|
||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g:h")), U("g:h")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g")), U("http://a/b/c/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("./g")), U("http://a/b/c/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g/")), U("http://a/b/c/g/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("/g")), U("http://a/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("//g")), U("http://g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("?y")), U("http://a/b/c/d;p?y")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g?y")), U("http://a/b/c/g?y")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("#s")), U("http://a/b/c/d;p?q#s")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g#s")), U("http://a/b/c/g#s")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g?y#s")), U("http://a/b/c/g?y#s")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U(";x")), U("http://a/b/c/;x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g;x")), U("http://a/b/c/g;x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g;x?y#s")), U("http://a/b/c/g;x?y#s")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("")), U("http://a/b/c/d;p?q")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U(".")), U("http://a/b/c/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("./")), U("http://a/b/c/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("..")), U("http://a/b/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../")), U("http://a/b/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../g")), U("http://a/b/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../..")), U("http://a/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../../")), U("http://a/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../../g")), U("http://a/g")); | ||
} | ||
//5.4.2. Abnormal Examples https://tools.ietf.org/html/rfc3986#section-5.4.2 | ||
TEST(resolve_uri_abnormal) | ||
{ | ||
const uri baseUri = U("http://a/b/c/d;p?q"); | ||
|
||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../../../g")), U("http://a/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("../../../../g")), U("http://a/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("/./g")), U("http://a/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("/../g")), U("http://a/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g.")), U("http://a/b/c/g.")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U(".g")), U("http://a/b/c/.g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g..")), U("http://a/b/c/g..")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("..g")), U("http://a/b/c/..g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("./../g")), U("http://a/b/g")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("./g/.")), U("http://a/b/c/g/")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g/./h")), U("http://a/b/c/g/h")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g/../h")), U("http://a/b/c/h")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g;x=1/./y")), U("http://a/b/c/g;x=1/y")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g;x=1/../y")), U("http://a/b/c/y")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g?y/./x")), U("http://a/b/c/g?y/./x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g?y/../x")), U("http://a/b/c/g?y/../x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g#s/./x")), U("http://a/b/c/g#s/./x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("g#s/../x")), U("http://a/b/c/g#s/../x")); | ||
VERIFY_ARE_EQUAL(baseUri.resolve_uri(U("http:g")), U("http:g")); | ||
} | ||
|
||
} // SUITE(resolve_uri_tests) | ||
|
||
}}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.