Skip to content

Commit

Permalink
[js] Normalize when encoding as utf8-c8
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Feb 2, 2018
1 parent 54b8395 commit 63320aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vm/js/nqp-runtime/codecs.js
Expand Up @@ -213,12 +213,13 @@ class Utf8C8 {
}

encode(str) {
const buf = new Buffer(Buffer.byteLength(str));
const normalized = str.normalize('NFC');
const buf = new Buffer(Buffer.byteLength(normalized));
let state = 0;
let offset = 0;
let byte = 0;

for (const c of str) {
for (const c of normalized) {
if (state === 0) {
if (c === '\u{10FFFD}') {
state = 1;
Expand Down

0 comments on commit 63320aa

Please sign in to comment.