tc39 / ecma262

Status, process, and documents for ECMA-262

Home Page:https://tc39.es/ecma262/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Encoding and decoding issues of `<script>` characters using decodeURIComponent and encodeURIComponent

TongKings opened this issue · comments

commented

The following cases were tested:
decodeURIComponent(encodeURIComponent("<script>"));
output: '\x3Cscript>'
But I used other cases and didn't get this problem.
PS: We can eliminate this problem using dual encoding and decoding,as follows:

const str = "<script>";
const encodedStr = encodeURIComponent(encodeURIComponent(str));
const decodedStr = decodeURIComponent(decodeURIComponent(encodedStr));
console.log(decodedStr);
output: "<script>"
Is this a legacy issue?

What problem exactly?

commented

What problem exactly?

OK, I didn’t explain it clearly before. Compare the following two cases:

f12e4ced1ffbb243bd22196c60e36a5

Here, the output using script string encoding and then decoding is inconsistent with the output using style etc. strings.

This confuses me, on our website we get this error

I don't get that in my browser - i get decodeURIComponent(encodeURIComponent('<script>')) === '<script>'.

What do Function.prototype.toString.call(decodeURIComponent) and Function.prototype.toString.call(encodeURIComponent) output?

This looks like an issue with Chrome dev-tools.

decodeURIComponent(encodeURIComponent('<script>')) === '<script>' is true in my chrome dev tools, but i do indeed see that the output is escaped on display.

I'll close this then, since it's a chrome-specific bug that should be filed there.

commented

decodeURIComponent(encodeURIComponent('<script>')) === '<script>'

ok,Thank you for your answer