Skip to content

Commit

Permalink
Fix handling of astral character reference
Browse files Browse the repository at this point in the history
Closes GH-158.
Closes remarkjs/remark#1251.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
Porges committed Oct 27, 2023
1 parent e0dce3d commit 6db3b42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {codes, values} from 'micromark-util-symbol'
* Turn the number (in string form as either hexa- or plain decimal) coming from
* a numeric character reference into a character.
*
* Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes
* Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes
* non-characters and control characters safe.
*
* @param {string} value
Expand Down Expand Up @@ -38,5 +38,5 @@ export function decodeNumericCharacterReference(value, base) {
return values.replacementCharacter
}

return String.fromCharCode(code)
return String.fromCodePoint(code)
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ There is no default export.
Turn the number (in string form as either hexa- or plain decimal) coming from
a numeric character reference into a character.

Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes
Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes
non-characters and control characters safe.

###### Parameters
Expand Down
6 changes: 6 additions & 0 deletions test/io/text/character-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ test('character-reference', function () {
'should support hexadecimal character references'
)

assert.equal(
micromark('片&#xE0103;'),
'<p>片\u{E0103}</p>',
'should support astral character references'
)

assert.equal(
micromark(
[
Expand Down

0 comments on commit 6db3b42

Please sign in to comment.