Skip to content
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

URL with base is always used, even when absolute URL is provided #26006

Closed
phallguy opened this issue Aug 10, 2019 · 8 comments
Closed

URL with base is always used, even when absolute URL is provided #26006

phallguy opened this issue Aug 10, 2019 · 8 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@phallguy
Copy link

MDN documentation for URL states that the base should only be used when url is a relative url. However the current implementation of URL (as of 0.60.4) in react-native always prepends the base if given.

React Native version:

System:
OS: macOS 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 447.55 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.6.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: ^16.9.0 => 16.9.0
react-native: 0.60.4 => 0.60.4
npmGlobalPackages:
react-native-cli: 2.0.1

Steps To Reproduce

const url = new URL("http://github.com", "http://google.com")
console.log(url.toString()) // => "http://google.comhttp://github.com"

Describe what you expected to happen:

const url = new URL("http://github.com", "http://google.com")
console.log(url.toString()) // => "http://github.com"

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@phallguy/url-bug-report

Notice that if you view the snack with the "Web" preview, it is handled correctly.

@phallguy phallguy added the Bug label Aug 10, 2019
@phallguy
Copy link
Author

Related to #16434

@jeswinsimon
Copy link
Contributor

jeswinsimon commented Aug 10, 2019

Would this be a valid fix for this?

@phallguy
Copy link
Author

Yes that looks like it would probably do the trick.

@jeswinsimon
Copy link
Contributor

Ok. I will open a PR then.

@phallguy
Copy link
Author

Unfortunately, I think the proposed change is going to break access to localhost. See #26019

@jeswinsimon
Copy link
Contributor

jeswinsimon commented Aug 11, 2019

Unfortunately, I think the proposed change is going to break access to localhost. See #26019

This is because the current validateBaseUrl expects a base url to be of the format domain-name.extension. I have proposed a fix in #26019.

facebook-github-bot pushed a commit that referenced this issue Aug 13, 2019
Summary:
Fix for bug #26006 URL with base is always used, even when absolute URL is provided

## Changelog

[Javascript] [Fixed] - `URL`: Base url value is ignored when the input url is not a relative url.
Pull Request resolved: #26009

Test Plan:
`new URL('http://github.com', 'http://google.com')` now returns `http://github.com/`
Added a test case to `URL-test.js` to verify the same.

Differential Revision: D16781921

Pulled By: cpojer

fbshipit-source-id: 038aca3610e34f513f603e8993f9a925b7d28626
@stale
Copy link

stale bot commented Nov 9, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 9, 2019
@stale
Copy link

stale bot commented Nov 16, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 16, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Nov 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants