-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: saxes handles chunks that "break" unicode
The way JavaScript handles unicode it is possible for a unicode string to be split in two such that a unicode code point is split into two parts: e.g. `` "\u{1F4A9}"[0]; "\u{1F4A9}"[1]`` If a large piece of data was cut up into smaller chunks that were fed in sequence to saxes, and it so happened that a unicode character was chopped up like illustrated above, then saxes would just raise an error and fail. Saxes now detects when a chunk ends with a surrogate and carries it over to the next chunk.
- Loading branch information
Showing
3 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
const { test } = require("."); | ||
|
||
describe("unicode test", () => { | ||
describe("poop", () => { | ||
const xml = "<a>💩</a>"; | ||
const expect = [ | ||
["opentagstart", { name: "a", attributes: {} }], | ||
["opentag", { name: "a", attributes: {}, isSelfClosing: false }], | ||
["text", "💩"], | ||
["closetag", { name: "a", attributes: {}, isSelfClosing: false }], | ||
]; | ||
|
||
test({ | ||
name: "intact", | ||
xml, | ||
expect, | ||
}); | ||
|
||
test({ | ||
name: "sliced", | ||
fn(parser) { | ||
// This test purposely slices the string into the poop character. | ||
parser.write(xml.slice(0, 4)); | ||
parser.write(xml.slice(4)); | ||
parser.close(); | ||
}, | ||
expect, | ||
}); | ||
}); | ||
}); |