Repository navigation
fix(lab-ops-hub): return empty path, userinfo and ?/# markers WHATWG-normalized (#639) #648
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,30 @@ test("validateCrawlUrl returns dot segments, host case and ports normalized (#63 | |
| } | ||
| }); | ||
|
|
||
| test("validateCrawlUrl returns empty components normalized (#639)", () => { | ||
| // The Worker's returned form is the reference the container validator | ||
| // mirrors: "/" supplied for an empty path, the empty port's colon and | ||
| // the empty userinfo's "@" dropped, and empty "?" / "#" markers kept | ||
| // (the query/fragment is present but empty). | ||
| const cases: Array<[string, string]> = [ | ||
| ["http://example.com", "http://example.com/"], | ||
| ["https://example.com", "https://example.com/"], | ||
| ["http://example.com:8080", "http://example.com:8080/"], | ||
| ["http://example.com:/path", "http://example.com/path"], | ||
| ["http://@example.com/", "http://example.com/"], | ||
| ["http://example.com/path?", "http://example.com/path?"], | ||
| ["http://example.com/path#", "http://example.com/path#"], | ||
| ["http://example.com?", "http://example.com/?"], | ||
| ["http://example.com/path?#", "http://example.com/path?#"], | ||
| ["http://[email protected]", "http://[email protected]/"], | ||
| ]; | ||
| for (const [raw, expected] of cases) { | ||
| const r = validateCrawlUrl(raw); | ||
| assert.equal(r.ok, true, raw); | ||
| if (r.ok) assert.equal(r.url, expected, raw); | ||
| } | ||
| }); | ||
|
|
||
| test("validateCrawlUrl refuses non-http schemes and junk", () => { | ||
| assert.equal(validateCrawlUrl("ftp://example.com/").ok, false); | ||
| assert.equal(validateCrawlUrl("file:///etc/passwd").ok, false); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -1002,6 +1002,67 @@ def test_redirect_handler_follows_the_normalized_target(self): | |
| ) | ||
| self.assertEqual(followed.full_url, "http://example.org/b") | ||
|
|
||
| def test_returns_empty_components_normalized(self): | ||
| # The container returned an empty path, an empty port and an | ||
| # empty userinfo verbatim while the Worker returns the | ||
| # WHATWG-normalized form, so the two crawlers recorded | ||
| # different URLs for the same target (#639). The returned URL | ||
| # now supplies "/" for an empty path and drops the empty | ||
| # userinfo's "@" (the empty port's colon is dropped by the | ||
| # #633 port canonicalization). Decision on the empty "?" / "#" | ||
| # markers urlparse cannot represent: preserve them, matching | ||
| # the Worker byte for byte — the query/fragment is present | ||
| # but empty. Verdicts are unchanged. | ||
| cases = { | ||
| "http://example.com": "http://example.com/", | ||
| "https://example.com": "https://example.com/", | ||
| "http://example.com:8080": "http://example.com:8080/", | ||
| "http://example.com:80": "http://example.com/", | ||
| "http://example.com:/path": "http://example.com/path", | ||
| "http://@example.com/": "http://example.com/", | ||
| "http://@example.com": "http://example.com/", | ||
| "http://@example.com/path?x#": "http://example.com/path?x#", | ||
| "http://example.com/path?": "http://example.com/path?", | ||
| "http://example.com/path#": "http://example.com/path#", | ||
| "http://example.com?": "http://example.com/?", | ||
| "http://example.com/path?#": "http://example.com/path?#", | ||
| "http://example.com#frag?notquery": ("http://example.com/#frag?notquery"), | ||
| "http://8.8.8.8": "http://8.8.8.8/", | ||
| "http://134744072": "http://8.8.8.8/", | ||
| "http://[2001:4860:4860::8888]": "http://[2001:4860:4860::8888]/", | ||
| "http://[email protected]": "http://[email protected]/", | ||
| "http://example.com/a/../b": "http://example.com/b", | ||
| # The markers survive the host-substitution rebuilds too: | ||
| # percent-decoded hosts and canonical IP literals are | ||
| # rebuilt with geturl() before normalization (#639). | ||
| "http://%65xample.com/path?": "http://example.com/path?", | ||
| "http://%65xample.com?": "http://example.com/?", | ||
| "http://8%2e8%2e8%2e8/path#": "http://8.8.8.8/path#", | ||
| "http://8%2e8%2e8%2e8?#": "http://8.8.8.8/?#", | ||
| } | ||
| for raw, expected in cases.items(): | ||
| self.assertEqual(validate_crawl_url(raw), expected, raw) | ||
| # Non-empty userinfo, query and fragment pass through | ||
| # byte-identical; a "?" inside the query or fragment is data. | ||
| self.assertAccepted("http://user:[email protected]/path?q=1#frag") | ||
| self.assertAccepted("http://example.com/pa?th#fr?ag") | ||
| # Blocked targets in these spellings are refused by the | ||
| # ordinary checks, for the right reason. | ||
| self.assertRefused("http://@127.0.0.1/") | ||
| self.assertRefused("http://127.0.0.1") | ||
| self.assertRefused("http://@localhost/") | ||
| # Redirect targets inherit the normalization (#639): the | ||
| # handler validates the raw Location and fetches the form | ||
| # validate_crawl_url returns. | ||
| import urllib.request | ||
|
|
||
| handler = app._ValidatingRedirectHandler() | ||
| req = urllib.request.Request("http://example.com/") | ||
| followed = handler.redirect_request( | ||
| req, None, 302, "Found", {}, "http://EXAMPLE.org" | ||
| ) | ||
| self.assertEqual(followed.full_url, "http://example.org/") | ||
|
|
||
| def test_percent_encodes_non_ascii_outside_the_host(self): | ||
| # WHATWG percent-encodes non-ASCII characters in the userinfo, | ||
| # path, query and fragment as UTF-8; urlparse hands them through | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an accepted URL has an empty query followed by a non-empty fragment, such as
http://example.com/path?#frag,geturl()first produceshttp://example.com/path#fragand this suffix append then returnshttp://example.com/path#frag?. The?has consequently become fragment data instead of preserving the empty query, diverging from the Worker/WHATWG resulthttp://example.com/path?#frag; the marker must be inserted before the fragment rather than appended to the whole serialization.Useful? React with 👍 / 👎.