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
,
Mar 3 2016
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"
,
Mar 3 2016
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 |
|||
Comment 1 by chrishtr@chromium.org
, Mar 2 2016Status: Untriaged (was: Unconfirmed)