Skip to content

Commit

Permalink
Prevent JSON.stringify from returning ill-formed Unicode strings
Browse files Browse the repository at this point in the history
Fixes #944
  • Loading branch information
gibson042 committed Jan 8, 2019
1 parent 85ce767 commit dcf7eb1
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -35984,15 +35984,18 @@ <h1>Runtime Semantics: SerializeJSONProperty ( _key_, _holder_ )</h1>
<emu-clause id="sec-quotejsonstring" aoid="QuoteJSONString">
<h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
<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>
<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>
<emu-alg>
1. Let _product_ be the String value consisting solely of the code unit 0x0022 (QUOTATION MARK).
1. For each code unit _C_ in _value_, do
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
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>.
1. For each code point _C_ in _cpList_, do
1. If _C_ is listed in the Code Point column of <emu-xref href="#table-json-single-character-escapes"></emu-xref>, then
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>.
1. Else if _C_ has a numeric value less than 0x0020 (SPACE), then
1. Set _product_ to the string-concatenation of _product_ and UnicodeEscape(_C_).
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
1. Let _unit_ be a code unit whose numeric value is that of _C_.
1. Set _product_ to the string-concatenation of _product_ and UnicodeEscape(_unit_).
1. Else,
1. Set _product_ to the string-concatenation of _product_ and _C_.
1. Set _product_ to the string-concatenation of _product_ and the <emu-xref aoid="UTF16Encoding"></emu-xref> of _C_.
1. Set _product_ to the string-concatenation of _product_ and the code unit 0x0022 (QUOTATION MARK).
1. Return _product_.
</emu-alg>
Expand All @@ -36001,7 +36004,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
<tbody>
<tr>
<th>
Code Unit Value
Code Point
</th>
<th>
Unicode Character Name
Expand All @@ -36012,7 +36015,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x0008`
U+0008
</td>
<td>
BACKSPACE
Expand All @@ -36023,7 +36026,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x0009`
U+0009
</td>
<td>
CHARACTER TABULATION
Expand All @@ -36034,7 +36037,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x000A`
U+000A
</td>
<td>
LINE FEED (LF)
Expand All @@ -36045,7 +36048,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x000C`
U+000C
</td>
<td>
FORM FEED (FF)
Expand All @@ -36056,7 +36059,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x000D`
U+000D
</td>
<td>
CARRIAGE RETURN (CR)
Expand All @@ -36067,7 +36070,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x0022`
U+0022
</td>
<td>
QUOTATION MARK
Expand All @@ -36078,7 +36081,7 @@ <h1>Runtime Semantics: QuoteJSONString ( _value_ )</h1>
</tr>
<tr>
<td>
`0x005C`
U+005C
</td>
<td>
REVERSE SOLIDUS
Expand Down

0 comments on commit dcf7eb1

Please sign in to comment.