[Pkg-javascript-commits] [node-expat] 236/371: adding a failing test for iconv

Jonas Smedegaard dr at jones.dk
Sun Feb 28 10:00:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-expat.

commit 025a60984ae5ccb2759ba58c143dc8bea97443e1
Author: julien <julien.genestoux at gmail.com>
Date:   Tue Jan 7 23:15:37 2014 +0100

    adding a failing test for iconv
---
 package.json |  3 ++-
 test.js      | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/package.json b/package.json
index 4dab99a..7ea8abb 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,8 @@
     "nan": "~0.6.0"
   },
   "devDependencies": {
-    "vows": ">=0.5.12"
+    "vows": ">=0.5.12",
+    "iconv": "*"
   },
   "repository": {
     "type": "git",
diff --git a/test.js b/test.js
index 95e1e5d..9cec0e4 100644
--- a/test.js
+++ b/test.js
@@ -1,4 +1,5 @@
 var expat = require('./lib/node-expat');
+var Iconv  = require('iconv').Iconv;
 var Buffer = require('buffer').Buffer;
 var vows = require('vows');
 var assert = require('assert');
@@ -198,6 +199,40 @@ vows.describe('node-expat').addBatch({
             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 = "?";
+            }
+            map[i] = d.charCodeAt(0);
+          }
+          console.log(map)
+          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': {
 	'tag name starting with ampersand': function() {
 	    expect("<&", [['error', "not well-formed (invalid token)"]]);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git



More information about the Pkg-javascript-commits mailing list