Closed
Bug 1145326
Opened 9 years ago
Closed 9 years ago
String.prototype.normalize error when normalization form parameter is not an atom
Categories
(Core :: JavaScript: Internationalization API, defect)
Tracking
()
RESOLVED
FIXED
mozilla39
Tracking | Status | |
---|---|---|
firefox39 | --- | fixed |
People
(Reporter: pathall, Assigned: evilpie)
Details
Attachments
(2 files)
931 bytes,
text/html
|
Details | |
1.96 KB,
patch
|
Waldo
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:37.0) Gecko/20100101 Firefox/37.0 Build ID: 20150305191659 Steps to reproduce: Assume a button with an id of "NFKC": <button id="NFKC">NFKC</button> Stick that string in a variable: var s1 = document.body.querySelector('#NFKC').id By way of comparison, assign the very same string to a variable directly: var s2 = 'NFKC' So of course: s1 === s2 // true And: s1 == s2 // true To normalize a string, you pass one of NFC, NFD, NFKC, or NFKD to .normalize(), like this: 'á'.normalize('NFKC') // "á" Depending on the normalization form you choose, you get different codepoints: 'á'.normalize('NFC').length == 1 // true 'á'.normalize('NFD').length == 2 // true Actual results: Since we know that s1 (the string we retrieved from the DOM) and s2 are THE SAME STRING (s1 === s2 is true), then obviously we can use either to normalize a string: 'á'.normalize(s2) "á" // well yeah, because s2 IS 'NFKC'. Naturally, s1 will behave exactly the same way, right? 'á'.normalize(s1) // RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD' Why the error here, but not with s2? Expected results: If I pass one of four strings corresponding to normalization forms to .normalize(), it should carry out normalization. Instead, I get a RangeError.
Reporter | ||
Comment 1•9 years ago
|
||
As pointed out on StackOverflow by Rick Hitchcock, the string doesn't have to be extracted from the DOM to cause the error: var s2 = 'NFKC'.split('').join(''); var s2 = 'NFKCabc'.replace('abc',''); Rick points out that this version this doesn't: var s2 = 'N'+'F'+'K'+'C'; http://stackoverflow.com/questions/29153533/when-a-string-is-not-a-string-unicode-normalization-weirdness-in-javascript#comment46529785_29153533
Assignee | ||
Updated•9 years ago
|
Component: Untriaged → JavaScript: Internationalization API
Product: Firefox → Core
Assignee | ||
Updated•9 years ago
|
Assignee: nobody → evilpies
Assignee | ||
Updated•9 years ago
|
Summary: String.prototype.normalize error when normalization form parameter is from the DOM → String.prototype.normalize error when normalization form parameter is not an atom
Assignee | ||
Comment 2•9 years ago
|
||
So the problem here is that the form parameter can be a "linear string", but not an atom. And of course if it's not an atom the pointer comparison to any atom is always going to fail.
Assignee | ||
Updated•9 years ago
|
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Assignee | ||
Comment 3•9 years ago
|
||
Attachment #8580637 -
Flags: review?(jwalden+bmo)
Comment 4•9 years ago
|
||
Comment on attachment 8580637 [details] [diff] [review] normalize Review of attachment 8580637 [details] [diff] [review]: ----------------------------------------------------------------- Oh fail, how did I review that. :-(
Attachment #8580637 -
Flags: review?(jwalden+bmo) → review+
Assignee | ||
Comment 5•9 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/8c968097ff98
Comment 6•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/8c968097ff98
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox39:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in
before you can comment on or make changes to this bug.
Description
•