New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 591307 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Mar 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

escape function works incorrect

Reported by alex1ki...@gmail.com, Mar 2 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36

Steps to reproduce the problem:
1. Open the Browser Console
2. Enter the following: escape(`<a>${3}</a>`) === (escape `<a>${3}</a>`)

What is the expected behavior?
result: true

What went wrong?
result: false

Did this work before? N/A 

Chrome version: 48.0.2564.116  Channel: n/a
OS Version: 6.3
Flash Version: Shockwave Flash 20.0 r0
 
Components: -Blink Blink>JavaScript
Status: Untriaged (was: Unconfirmed)
Cc: littledan@chromium.org yangguo@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Language
Labels: -OS-Windows OS-All
Status: Available (was: Untriaged)
Escape is deprecated. You should use encodeURI. But that does not work too:

> encodeURI(`<a>${3}</a>`)
< "%3Ca%3E3%3C/a%3E"
> encodeURI `<a>${3}</a>`
< "%3Ca%3E,%3C/a%3E"

Cc: caitpott...@gmail.com
Status: WontFix (was: Available)
I can reproduce this:
> encodeURI `${3}`
","
> encodeURI(`${3}`)
"3"

However, this is working as intended. When using the template literal with the tag syntax, the tag function is called with a list of string parts and the interpolated values as additional arguments. Consider this:

> function f(...rest) { console.log(rest)}
undefined
f `${3}`
> [["", ""], 3]

So basically, the encodeURI is called like this:
encodeURI(["", ""], 3)

encodeURI is not interested in the second argument. The first argument is converted to string, which is ",".

Adding Caitlyn to confirm.

Sign in to add a comment