Repository navigation
Conversation
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
new URL(url, base)appendsurltobaseinstead of resolving it, so many relative references give a different URL than Node'sURL:This change resolves the reference against the base as in RFC 3986 section 5.2: a path that starts with
/replaces the base path, any other path replaces the last segment of the base path,.and..segments are removed, and an empty path keeps the base path and query. A reference that starts with//is resolved too, instead of being returned as is. Calls without a base, and URLs thatvalidateBaseUrlaccepts other than ones starting with//, take the same branch as before.The test in
URL-itest.jsthat was commented out as requiring a complex implementation (/en-US/docsagainsthttps://developer.mozilla.org/fr-FR/toto) is enabled. #45055 worked on base URLs and relative paths before and was closed as stale.This follows RFC 3986, not the full WHATWG URL parser, so some differences from Node's
URLremain and are not changed here:validateBaseUrlstill rejects a base with credentials (https://user:pw@host/) or a custom scheme (myapp://); references with an empty host such as//or///xdiffer;http:gis treated as absolute, as in RFC 3986, where Node resolves it against anhttpbase; and Node also treats percent-encoded dot segments (%2e%2e/hi) as..and a backslash as/, and removes tabs and leading spaces, which this change does not.Changelog:
[GENERAL] [FIXED] - Resolve relative references against the base URL in the
URLconstructorTest Plan:
yarn fantom packages/react-native/Libraries/Blob/__tests__/URL-itest.js: 5 passed. WithURL.jsfrommain, 3 fail: the re-enabled MDN case and the two new tests.http://a.com/b/c/d;p?qbecausevalidateBaseUrlrejects the RFC'shttp://a/..., and expected values from Node'sURL; and//cdn.example.com/x.jsagainsthttps://example.com/.URLon 20,000 generated relative references (segments such as.,..,ganda;b, with queries, fragments and//host) against 10 base URLs:maindiffers in 16,910, this branch in 2,470, of which 1,651 have a base with credentials and 819 an empty host. In this generated sample, no reference that matched Node onmaindiffers after the change.yarn flow-check(Found 0 errors),yarn lint, andprettier --checkon the two files pass.