forked from isaacs/sax-js
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from jlank/utf8-fix
added fix for utf8 multi-byte boundary when it is split between chunks, ...
- Loading branch information
Showing
2 changed files
with
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var fs = require('fs') | ||
, clarinet = require('../clarinet.js') | ||
, chunks = clarinet.createStream() | ||
, assert = require('assert') | ||
; | ||
|
||
var han_value = '我'; | ||
var han_obj = '{"thing":"' + han_value + '"}'; | ||
var han_test_obj = ''; | ||
var han_buffer_first = new Buffer([0xe6, 0x88]); | ||
var han_buffer_second = new Buffer([0x91]); | ||
var han_buffer_full = new Buffer([0xe6, 0x88, 0x91]); | ||
|
||
describe('clarinet', function(){ | ||
describe('#utf8-chunks', function() { | ||
it('should be able to parse utf8 characters split across data chunks', function (done){ | ||
chunks.on("error", function (err) { done(err); }); | ||
chunks.on("data", function (data) { | ||
han_test_obj += data; | ||
}); | ||
chunks.on("end", function () { | ||
assert.equal(han_obj, han_test_obj); | ||
done(); | ||
}); | ||
|
||
chunks.write('{"thing":"'); | ||
chunks.write(han_buffer_first); | ||
chunks.write(han_buffer_second); | ||
//chunks.write(han_buffer_full); | ||
chunks.write('"}'); | ||
chunks.end(); | ||
}); | ||
}); | ||
}); |