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

Issue with "encodeURIComponent": Incorrect parametr's type #10093

Closed
ana-max opened this issue Oct 26, 2021 · 2 comments · Fixed by #10123
Closed

Issue with "encodeURIComponent": Incorrect parametr's type #10093

ana-max opened this issue Oct 26, 2021 · 2 comments · Fixed by #10123

Comments

@ana-max
Copy link

ana-max commented Oct 26, 2021

MDN URL:
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

I think the information about parametr's type is not correct.

The realization of this function (encodeURIComponent) you can find in
https://chromium.googlesource.com/v8/v8/+/3.30.3/src/uri.js?autodive=0%2F
on line 355-374.
As you can see on line 351 there is the cast function ToString
So, you can call this function not only with string arguments. You can call this function with boolean and number too.
TypeSctipt's signature of this method proves it too:

function encodeURIComponent(uriComponent: string | number | boolean): string

@ana-max ana-max changed the title Bug in documentation Issue with "encodeURIComponent" Oct 26, 2021
@ana-max ana-max changed the title Issue with "encodeURIComponent" Issue with "encodeURIComponent". Incorrect parametr's type Oct 26, 2021
@ana-max ana-max changed the title Issue with "encodeURIComponent". Incorrect parametr's type Issue with "encodeURIComponent": Incorrect parametr's type Oct 26, 2021
@jyotijangid
Copy link
Contributor

jyotijangid commented Oct 26, 2021

I agree with you that the information about the paramter's type is actually incomplete.

When checked encodeURIComponent with other datatypes i.e number, Boolean, null as parameters.

encodeURIComponent('test'); // test
encodeURIComponent(23.56); // 23.56
encodeURIComponent(true); // true
encodeURIComponent(null); // null

When the encodeURIComponent function is called with one argument uriComponent, the following steps are taken:

  1. Let componentString be ? ToString(uriComponent).

Every uriComponent gets type casted to String using ToString first.

Ref - https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

@jyotijangid
Copy link
Contributor

I would like to work on this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants