node-expat
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -25,2 +25,6 @@ var EventEmitter = require('events').EventEmitter; | ||
Parser.prototype.setUnknownEncoding = function(map, convert) { | ||
return this.parser.setUnknownEncoding(map, convert); | ||
}; | ||
Parser.prototype.getError = function() { | ||
@@ -27,0 +31,0 @@ return this.parser.getError(); |
{ | ||
"name": "node-expat", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"main": "./lib/node-expat", | ||
@@ -21,3 +21,4 @@ "description": "NodeJS binding for fast XML parsing.", | ||
"devDependencies": { | ||
"vows": ">=0.5.12" | ||
"vows": ">=0.5.12", | ||
"iconv": "~2.1.0" | ||
}, | ||
@@ -54,3 +55,4 @@ "repository": { | ||
"Tom Hughes-Croucher", | ||
"Nathan Rajlich" | ||
"Nathan Rajlich", | ||
"Julien Genestoux" | ||
], | ||
@@ -57,0 +59,0 @@ "licenses": [ |
65
test.js
var expat = require('./lib/node-expat'); | ||
var Iconv = require('iconv').Iconv; | ||
var Buffer = require('buffer').Buffer; | ||
@@ -27,3 +28,3 @@ var vows = require('vows'); | ||
for(var step = s.length; step > 0; step--) { | ||
expectWithParserAndStep(s, evs_expected, new expat.Parser("UTF-8"), step); | ||
expectWithParserAndStep(s, evs_expected, new expat.Parser(), step); | ||
} | ||
@@ -34,3 +35,2 @@ } | ||
var evs_received = []; | ||
//p.setEncoding("UTF-8"); | ||
p.addListener('startElement', function(name, attrs) { | ||
@@ -176,2 +176,63 @@ evs_received.push(['startElement', name, attrs]); | ||
}, | ||
'unknownEncoding with single-byte map': { | ||
'Windows-1252': function() { | ||
var p = new expat.Parser(); | ||
var encodingName; | ||
p.addListener('unknownEncoding', function(name) { | ||
encodingName = name; | ||
var map = []; | ||
for(var i = 0; i < 256; i++) | ||
map[i] = i; | ||
map[165] = 0x00A5; // ¥ | ||
map[128] = 0x20AC; // € | ||
map[ 36] = 0x0024; // $ | ||
p.setUnknownEncoding(map); | ||
}); | ||
var text = ""; | ||
p.addListener('text', function(s) { | ||
text += s; | ||
}); | ||
p.addListener('error', function(e) { | ||
assert.fail(e); | ||
}); | ||
p.parse("<?xml version='1.0' encoding='Windows-1252'?><r>"); | ||
p.parse(new Buffer([165, 128, 36])); | ||
p.parse("</r>"); | ||
assert.equal(encodingName, "Windows-1252"); | ||
assert.equal(text, "¥€$"); | ||
} | ||
}, | ||
'unknownEncoding with single-byte map using iconv': { | ||
'Windows-1252': function() { | ||
var p = new expat.Parser(); | ||
var encodingName; | ||
p.addListener('unknownEncoding', function(name) { | ||
encodingName = name; | ||
var iconv = new Iconv(encodingName + '//TRANSLIT//IGNORE', 'UTF-8'); | ||
var map = []; | ||
for(var i = 0; i < 256; i++) { | ||
try { | ||
var d = iconv.convert(new Buffer([i])).toString(); | ||
} catch (e) { | ||
d = '\b'; | ||
} | ||
map[i] = d.charCodeAt(0); | ||
} | ||
p.setUnknownEncoding(map); | ||
}); | ||
var text = ""; | ||
p.addListener('text', function(s) { | ||
text += s; | ||
}); | ||
p.addListener('error', function(e) { | ||
assert.fail(e); | ||
}); | ||
p.parse("<?xml version='1.0' encoding='Windows-1252'?><r>"); | ||
p.parse(new Buffer([165, 128, 36])); | ||
p.parse("</r>"); | ||
assert.equal(encodingName, "Windows-1252"); | ||
assert.equal("¥€$", text); | ||
} | ||
}, | ||
'error': { | ||
@@ -178,0 +239,0 @@ 'tag name starting with ampersand': function() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3964048
616
103
2