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

Update encodeURIComponent() parameter information #10123

Merged
merged 5 commits into from Oct 30, 2021

Conversation

jyotijangid
Copy link
Contributor

@jyotijangid jyotijangid commented Oct 27, 2021

Summary

Parameter changed to uriComponent which can be a string, number, boolean, null, undefined or any other object.

Motivation

Before encoding uriComponent is typecasted to string, using toString method.

Supporting details

const obj1 = false
const obj2 = null

console.log(`${encodeURIComponent(obj1)}`) //false
console.log(typeof `${encodeURIComponent(obj1)}`) //string
console.log(`${encodeURIComponent(obj2)}`) //null
console.log(typeof `${encodeURIComponent(obj2)}`) //string

const book = {
    name:"The Alchemist",
    author:"Paulo Coelho",
    toString: function(){
        return this.name + " by " + this.author
    }
}

console.log(`${encodeURIComponent(book)}`) //The%20Alchemist%20by%20Paulo%20Coelho //first toString method is called, then encoding

Ref - https://tc39.es/ecma262/multipage/global-object.html#sec-encodeuricomponent-uricomponent
Similar issue was raised in TypeScript - microsoft/TypeScript#18159

Related issues

Fixes #10093

Metadata

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

@jyotijangid jyotijangid requested a review from a team as a code owner October 27, 2021 17:18
@jyotijangid jyotijangid requested review from sideshowbarker and removed request for a team October 27, 2021 17:18
@github-actions github-actions bot added the Content:JS JavaScript docs label Oct 27, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 2021

Preview URLs

Flaws

None! 🎉

External URLs

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Title: encodeURIComponent()
on GitHub

No new external URLs

(this comment was updated 2021-10-30 02:15:01.573959)

@jyotijangid jyotijangid changed the title Issue 10093 Parameter changed to uriComponent which can be string, number, Boolean, other objects Oct 27, 2021
@jyotijangid jyotijangid changed the title Parameter changed to uriComponent which can be string, number, Boolean, other objects Parameter changed to uriComponent which can be string, number, boolean, other objects Oct 27, 2021
@jyotijangid jyotijangid marked this pull request as draft October 27, 2021 17:39
@jyotijangid jyotijangid marked this pull request as ready for review October 29, 2021 16:45
@sideshowbarker sideshowbarker changed the title Parameter changed to uriComponent which can be string, number, boolean, other objects Update encodeURIComponent() parameter information Oct 30, 2021
@sideshowbarker sideshowbarker merged commit 97dc5a2 into mdn:main Oct 30, 2021
@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
Content:JS JavaScript docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with "encodeURIComponent": Incorrect parametr's type
2 participants