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

Finish implementing URL accessors like host, hostname, username, password #45030

Open
kross-italk opened this issue Jun 18, 2024 · 12 comments · May be fixed by #45055 or #48333
Open

Finish implementing URL accessors like host, hostname, username, password #45030

kross-italk opened this issue Jun 18, 2024 · 12 comments · May be fixed by #45055 or #48333
Assignees
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Triage 🔍 Newer Patch Available

Comments

@kross-italk
Copy link

kross-italk commented Jun 18, 2024

Description

The window.URL object is available in Hermes but is otherwise un-implemented. All of the accessors have todo Errors.

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}`;
}
}
get hash(): string {
throw new Error('URL.hash is not implemented');
}
get host(): string {
throw new Error('URL.host is not implemented');
}
get hostname(): string {
throw new Error('URL.hostname is not implemented');
}
get href(): string {
return this.toString();
}
get origin(): string {
throw new Error('URL.origin is not implemented');
}
get password(): string {
throw new Error('URL.password is not implemented');
}
get pathname(): string {
throw new Error('URL.pathname not implemented');
}
get port(): string {
throw new Error('URL.port is not implemented');
}
get protocol(): string {
throw new Error('URL.protocol is not implemented');
}
get search(): string {
throw new Error('URL.search is not implemented');
}
get searchParams(): URLSearchParams {
if (this._searchParamsInstance == null) {
this._searchParamsInstance = new URLSearchParams();
}
return this._searchParamsInstance;
}
toJSON(): string {
return this.toString();
}
toString(): string {
if (this._searchParamsInstance === null) {
return this._url;
}
// $FlowFixMe[incompatible-use]
const instanceString = this._searchParamsInstance.toString();
const separator = this._url.indexOf('?') > -1 ? '&' : '?';
return this._url + separator + instanceString;
}
get username(): string {

Steps to reproduce

const urlObj = new window.URL( validUrlString );
urlObj.hostname
// Error: URL.hostname is not implemented

React Native Version

0.73.6

Affected Platforms

Runtime - Android

Output of npx react-native info

Reproducible on all systems. The code has a baked-in Error and no implementation.

Stacktrace or Logs

This error is located at:
    in SecureContext (created by Connect(SecureContext))
    in Connect(SecureContext) (created by App)
    in RCTView (created by View)
    in View (created by App)
    in App (created by RenderApp)
    in Provider (created by RenderApp)
    in RenderApp
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in app(RootComponent), js engine: hermes

Reproducer

https://snack.expo.dev/O0xP_moxLBNEHK9bXAXKl
It can't be reproduced in a browser folks. It can only be seen on hermes/Android so this is moot.

Screenshots and Videos

No response

Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.73.8. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jun 18, 2024
@kross-italk
Copy link
Author

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.73.8. Please [upgrade]

Here's the latest version of the code showing the features are still un-implemented.

get hash(): string {
throw new Error('URL.hash is not implemented');
}
get host(): string {
throw new Error('URL.host is not implemented');
}
get hostname(): string {
throw new Error('URL.hostname is not implemented');
}
get href(): string {
return this.toString();
}
get origin(): string {
throw new Error('URL.origin is not implemented');
}
get password(): string {
throw new Error('URL.password is not implemented');
}
get pathname(): string {
throw new Error('URL.pathname not implemented');
}
get port(): string {
throw new Error('URL.port is not implemented');
}
get protocol(): string {
throw new Error('URL.protocol is not implemented');
}
get search(): string {
throw new Error('URL.search is not implemented');
}
get searchParams(): URLSearchParams {
if (this._searchParamsInstance == null) {
this._searchParamsInstance = new URLSearchParams();
}
return this._searchParamsInstance;
}
toJSON(): string {
return this.toString();
}

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jun 18, 2024
@cortinico cortinico added Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Attention Issues where the author has responded to feedback. labels Jun 18, 2024
@sossost
Copy link

sossost commented Jun 18, 2024

@cortinico
Hi I'm sossost, a new contributor. Can I try to resolve this issue??

@cortinico
Copy link
Contributor

Please do 👍

@Shiva710211
Copy link

Hi I'm Shivanand, the new contributor. Can i try to resolve this issue? Please provide me with brief information about this issue

sossost added a commit to sossost/react-native that referenced this issue Jun 26, 2024
@nirmalkumarnikam
Copy link

Hey I learned JS and Version Control few days ago, I am willing to contribute... I don't know how to get started... Can someone help me with it?

SarhaneGhribi pushed a commit to SarhaneGhribi/react-native that referenced this issue Nov 13, 2024
@Ghanasree
Copy link

Hi, Is this issue still open? If it is I would like to work on it. Thanks

@krishpranav
Copy link

@cortinico
Hi I'm krishpranav, a new contributor. Can I try to resolve this issue??

@krishpranav
Copy link

I am working on the fix for this issue.

@cortinico
Copy link
Contributor

There is already an open PR to address this:

@krishpranav
Copy link

can you let me know whether shall I work on this issue or not? I am a first time contributor to this repo.

@krishpranav
Copy link

@cortinico I've opened a new pull-request, can you kindly check that and let me know. also is there any untouched or anything which is uncompleted one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Triage 🔍 Newer Patch Available
Projects
None yet
7 participants