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 constructor not spec compliant #49856

Open
Upsilon-Iridani opened this issue Mar 6, 2025 · 5 comments
Open

URL constructor not spec compliant #49856

Upsilon-Iridani opened this issue Mar 6, 2025 · 5 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Version Info

Comments

@Upsilon-Iridani
Copy link

Description

When supplying the URL constructor with a second argument, 'base', paths aren't resolved correctly. see https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#base

The error is visible here:

constructor(url: string, base?: string | URL) {
let baseUrl = null;
if (!base || validateBaseUrl(url)) {
this._url = url;
if (!this._url.endsWith('/')) {
this._url += '/';
}
} else {
if (typeof base === 'string') {
baseUrl = base;
if (!validateBaseUrl(baseUrl)) {
throw new TypeError(`Invalid base URL: ${baseUrl}`);
}
} else {
baseUrl = base.toString();
}
if (baseUrl.endsWith('/')) {
baseUrl = baseUrl.slice(0, baseUrl.length - 1);
}
if (!url.startsWith('/')) {
url = `/${url}`;
}
if (baseUrl.endsWith(url)) {
url = '';
}
this._url = `${baseUrl}${url}`;
}
}

Steps to reproduce

console.log(new URL('/absolute/path', 'https://example.com/base-url/').href);
// prints:       https://example.com/base-url/absolute/path
// expected:     https://example.com/absolute/path

React Native Version

0.73

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

N/A

Stacktrace or Logs

N/A

Reproducer

N/A

Screenshots and Videos

No response

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Mar 6, 2025
@react-native-bot
Copy link
Collaborator

Warning

Could not parse version: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.76.2.

@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@react-native-bot
Copy link
Collaborator

Warning

Could not parse version: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.76.2.

@cipolleschi
Copy link
Contributor

@Upsilon-Iridani 0.73 is out of support and it won't receive any further updates. The oldest supported version right now is 0.76. Can you check if the problem persists there as well?

@Upsilon-Iridani
Copy link
Author

I could only reproduce it in a snack by selecting expo 0.49, so it might already be solved. Then the code I linked in the issue should probably be deleted, as it appears dead/unused.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Version Info
Projects
None yet
Development

No branches or pull requests

3 participants