sax 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/sax.js CHANGED
@@ -278,11 +278,13 @@ function write (chunk) {
278
278
  var starti = i-1;
279
279
  while (c && c!=="<" && c!=="&") {
280
280
  c = chunk.charAt(i++);
281
- parser.position ++;
282
- if (c === "\n") {
283
- parser.line ++;
284
- parser.column = 0;
285
- } else parser.column ++;
281
+ if (c) {
282
+ parser.position ++;
283
+ if (c === "\n") {
284
+ parser.line ++;
285
+ parser.column = 0;
286
+ } else parser.column ++;
287
+ }
286
288
  }
287
289
  parser.textNode += chunk.substring(starti, i-1);
288
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  { "name" : "sax"
2
2
  , "author" : "Isaac Z. Schlueter <i@izs.me>"
3
- , "version" : "0.1.4"
3
+ , "version" : "0.1.5"
4
4
  , "main" : "lib/sax"
5
5
  , "license" : "MIT"
6
6
  , "scripts" : { "test" : "node test/index.js" }
@@ -0,0 +1,27 @@
1
+ var sax = require("../lib/sax"),
2
+ assert = require("assert")
3
+
4
+ function testPosition(chunks, expectedEvents) {
5
+ var parser = sax.parser();
6
+ expectedEvents.forEach(function(expectation) {
7
+ parser['on' + expectation[0]] = function() {
8
+ assert.equal(parser.position, expectation[1]);
9
+ }
10
+ });
11
+ chunks.forEach(function(chunk) {
12
+ parser.write(chunk);
13
+ });
14
+ };
15
+
16
+ testPosition(['<div>abcdefgh</div>'],
17
+ [ ['opentag', 5]
18
+ , ['text', 19]
19
+ , ['closetag', 19]
20
+ ]);
21
+
22
+ testPosition(['<div>abcde','fgh</div>'],
23
+ [ ['opentag', 5]
24
+ , ['text', 19]
25
+ , ['closetag', 19]
26
+ ]);
27
+