Skip to content

Commit 7428c89

Browse files
gibson042bterlson
authored andcommitted
Normative: Prevent JSON.stringify from returning ill-formed Unicode strings (#1396)
Fixes #944
1 parent 5a652f9 commit 7428c89

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

spec.html

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36157,15 +36157,18 @@ <h1>Runtime Semantics: SerializeJSONProperty ( _key_, _holder_ )</h1>
3615736157
<emu-clause id="sec-quotejsonstring" aoid="QuoteJSONString">
3615836158
<h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3615936159
<p>The abstract operation QuoteJSONString with argument _value_ wraps a String value in QUOTATION MARK code units and escapes certain other code units within it.</p>
36160+
<p>This operation interprets a String value as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p>
3616036161
<emu-alg>
3616136162
1. Let _product_ be the String value consisting solely of the code unit 0x0022 (QUOTATION MARK).
36162-
1. For each code unit _C_ in _value_, do
36163-
1. If the numeric value of _C_ is listed in the Code Unit Value column of <emu-xref href="#table-json-single-character-escapes"></emu-xref>, then
36163+
1. Let _cpList_ be a List containing in order the code points of _value_ when interpreted as a sequence of UTF-16 encoded code points as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.
36164+
1. For each code point _C_ in _cpList_, do
36165+
1. If _C_ is listed in the Code Point column of <emu-xref href="#table-json-single-character-escapes"></emu-xref>, then
3616436166
1. Set _product_ to the string-concatenation of _product_ and the Escape Sequence for _C_ as specified in <emu-xref href="#table-json-single-character-escapes"></emu-xref>.
36165-
1. Else if _C_ has a numeric value less than 0x0020 (SPACE), then
36166-
1. Set _product_ to the string-concatenation of _product_ and UnicodeEscape(_C_).
36167+
1. Else if _C_ has a numeric value less than 0x0020 (SPACE), or _C_ has the same numeric value as a <emu-xref href="#leading-surrogate"></emu-xref> or <emu-xref href="#trailing-surrogate"></emu-xref>, then
36168+
1. Let _unit_ be a code unit whose numeric value is that of _C_.
36169+
1. Set _product_ to the string-concatenation of _product_ and UnicodeEscape(_unit_).
3616736170
1. Else,
36168-
1. Set _product_ to the string-concatenation of _product_ and _C_.
36171+
1. Set _product_ to the string-concatenation of _product_ and the <emu-xref aoid="UTF16Encoding"></emu-xref> of _C_.
3616936172
1. Set _product_ to the string-concatenation of _product_ and the code unit 0x0022 (QUOTATION MARK).
3617036173
1. Return _product_.
3617136174
</emu-alg>
@@ -36174,7 +36177,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3617436177
<tbody>
3617536178
<tr>
3617636179
<th>
36177-
Code Unit Value
36180+
Code Point
3617836181
</th>
3617936182
<th>
3618036183
Unicode Character Name
@@ -36185,7 +36188,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3618536188
</tr>
3618636189
<tr>
3618736190
<td>
36188-
`0x0008`
36191+
U+0008
3618936192
</td>
3619036193
<td>
3619136194
BACKSPACE
@@ -36196,7 +36199,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3619636199
</tr>
3619736200
<tr>
3619836201
<td>
36199-
`0x0009`
36202+
U+0009
3620036203
</td>
3620136204
<td>
3620236205
CHARACTER TABULATION
@@ -36207,7 +36210,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3620736210
</tr>
3620836211
<tr>
3620936212
<td>
36210-
`0x000A`
36213+
U+000A
3621136214
</td>
3621236215
<td>
3621336216
LINE FEED (LF)
@@ -36218,7 +36221,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3621836221
</tr>
3621936222
<tr>
3622036223
<td>
36221-
`0x000C`
36224+
U+000C
3622236225
</td>
3622336226
<td>
3622436227
FORM FEED (FF)
@@ -36229,7 +36232,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3622936232
</tr>
3623036233
<tr>
3623136234
<td>
36232-
`0x000D`
36235+
U+000D
3623336236
</td>
3623436237
<td>
3623536238
CARRIAGE RETURN (CR)
@@ -36240,7 +36243,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3624036243
</tr>
3624136244
<tr>
3624236245
<td>
36243-
`0x0022`
36246+
U+0022
3624436247
</td>
3624536248
<td>
3624636249
QUOTATION MARK
@@ -36251,7 +36254,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
3625136254
</tr>
3625236255
<tr>
3625336256
<td>
36254-
`0x005C`
36257+
U+005C
3625536258
</td>
3625636259
<td>
3625736260
REVERSE SOLIDUS

0 commit comments

Comments
 (0)