Skip to content

Support astral symbols #4

Description

@mathiasbynens
> htmlentities.decode('𝌆') // U+1D306 TETRAGRAM FOR CENTRE
'\uD306' // should be `\uD834\uDF06` i.e. `𝌆`

E.g. © decodes just fine, but 𝌆 doesn’t because String.fromCharCode(0x1D306) doesn’t work for astral values (i.e. values > 0xFFFF). U+1D306 is an astral symbol. Details here: http://mathiasbynens.be/notes/javascript-encoding

This can easily be fixed by using the Punycode module:

// Instead of…
String.fromCharCode(codePoint);
// …which only works for values from 0x0000 to 0xFFFF, use this:
punycode.ucs2.encode([ codePoint ]);
// …which works for all Unicode code points (i.e. values from 0x000000 to 0x10FFFF)

(Note: Punycode.js is bundled with Node.js v0.6.2+ but you could always add it to package.json anyway if you want to support older versions).

See he’s he.decode() for a working example that doesn’t rely on Punycode.js.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions