Closed
Bug 586994
Opened 15 years ago
Closed 14 years ago
toSource of function does not return valid source code if identifier contains unicode characters
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
DUPLICATE
of bug 621814
People
(Reporter: cluidolt, Unassigned)
Details
Attachments
(2 files)
|
587 bytes,
text/html
|
Details | |
|
599 bytes,
patch
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729; .NET4.0C)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729; .NET4.0C)
All characters in identifiers with an code greater than 127 are escaped - it is not allowed to use escape sequences in Javascript identifiers.
It seems that the same algorithm is also used to encode the keys of javascript objects - here quotes would solve the problem (Note that for compatibility I also would recommend to quote reserved words like 'class', 'null'...)
Reproducible: Always
Steps to Reproduce:
1. create a HTML file with the following content
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>test</title>
<meta name="content-type" content="text/html; charset=utf-8" />
</head>
<body style="white-space: pre;">
<script type="text/javascript">
function test() {
var ü = {"class":1, "null": null, "ä ö ü": 2};
}
document.writeln(test);
test = test.toSource();
document.writeln(test);
try {
eval(test)
}
catch (exc) {
document.writeln("Exception: " + exc);
}
</script>
</body>
</html>
2. open this file in Firefox
Actual Results:
- you can see that no valid source is generated and eval fails with "SyntaxError: illegal character"
Expected Results:
a valid source code should be printed and no eval should work without exception.
| Reporter | ||
Comment 1•15 years ago
|
||
| Reporter | ||
Comment 2•15 years ago
|
||
| Reporter | ||
Comment 3•15 years ago
|
||
there is also a problem with the following line of code when getting the source with .toSource()
obj["\u00c6"] = "\u00c6";
will be converted to
obj.\xC6 = "\xC6";
Updated•14 years ago
|
Assignee: general → evilpies
Updated•14 years ago
|
Assignee: evilpies → general
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → WORKSFORME
Updated•14 years ago
|
Flags: in-testsuite?
Updated•14 years ago
|
Resolution: WORKSFORME → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•