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.href has an extraneous slash #31082

Conversation

fabOnReact
Copy link
Contributor

@fabOnReact fabOnReact commented Mar 2, 2021

Summary

This issue fixes #30914
The logic of adding extraneous slash to url was introduced with pr #22901 but It should be removed for the following reasons:

Changelog

[Android] [Fixed] - Avoid adding extraneous slash to end of url

Test Plan

TODO:

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 2, 2021
@analysis-bot
Copy link

analysis-bot commented Mar 2, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: ede065c

@analysis-bot
Copy link

analysis-bot commented Mar 2, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,903,236 -246
android hermes armeabi-v7a 8,400,395 -253
android hermes x86 9,392,274 -245
android hermes x86_64 9,336,368 -246
android jsc arm64-v8a 10,637,277 -280
android jsc armeabi-v7a 10,117,539 -276
android jsc x86 10,687,830 -267
android jsc x86_64 11,272,185 -273

Base commit: ede065c

@fabOnReact
Copy link
Contributor Author

fabOnReact commented Mar 2, 2021

@fabOnReact fabOnReact marked this pull request as ready for review March 15, 2021 15:55
@yungsters
Copy link
Contributor

I left a comment here: #30914 (comment)

While this does fix a bug, it introduces another bug. If we are going to make a change to URL at this point (which would be a breaking change for someone), we should probably go for the correct behavior.

I believe the correct behavior will require parsing supplied URLs into each parts in order to do proper path formatting (and / insertion).

@fabOnReact
Copy link
Contributor Author

fabOnReact commented May 19, 2021

Thanks a lot Timothy Yung.

I include this information to help myself troubleshoot this issue.
We currently don't compute the base when running this test

    const b = new URL('https://developer.mozilla.org');
    expect(b.href).toBe('https://developer.mozilla.org/');

Instead we just add the / at the end of the entire string/url, without identifying baseUrl and path.

constructor(url: string, base: string) {
let baseUrl = null;
if (!base || validateBaseUrl(url)) {
this._url = url;
if (!this._url.endsWith('/')) {
this._url += '/';
}

I am looking into the whatwg-url URL-impl, debugging basicURLParse by running the test suite, reading the specs and hopefully I will be able to add it soon to react-native.

Thanks a lot 🙏

@fabOnReact fabOnReact marked this pull request as draft May 19, 2021 23:27
@fabOnReact
Copy link
Contributor Author

whatwg-url uses parse host, parseHost functions to parse the host from the url.

Other functions will handle other required aspects of parsing and formatting urls.

#22901 (comment)

This looks fine for me for now. I wonder if there is a third-party dep for URL we could use instead of maintaining our own copy?

I'm considering using basicURLParse imported via the whatwg-url npm package to parse supplied URLs into each parts in order to do proper path formatting (and / insertion).

Thanks a lot 🙏

@yungsters
Copy link
Contributor

If we're going to pull in whatwg-url, would it make sense to directly depend on its URL implementation entirely?

My only concern would be the size of the library introduced into React Native. On the one hand… this module should only need to be initialized if it is used. On the other hand… it still introduces weight to app binaries.

Taking a step back, though… since we already provide URL, we owe it to the platform to provide a proper implementation of it. (If app size were a concern, I propose that we tackle that as a separate follow-up discussion.)

@fabOnReact fabOnReact closed this Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL.href has an extraneous slash
4 participants