Skip to content

Commit

Permalink
Fixed cdata position reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Feb 4, 2019
1 parent 93c2c87 commit 28d5956
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Binary file modified lib/sax-wasm.wasm
Binary file not shown.
7 changes: 4 additions & 3 deletions src/js/__test__/cdada.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {SaxEventType, SAXParser} = require('../../../lib/');
const { SaxEventType, SAXParser } = require('../../../lib/');
const fs = require('fs');
const path = require('path');
const expect = require('expect.js');
Expand All @@ -9,7 +9,7 @@ describe('When parsing XML, the SaxWasm', () => {
let _event;
let _data;
before(async () => {
parser = new SAXParser(SaxEventType.Cdata);
parser = new SAXParser(SaxEventType.Cdata | SaxEventType.OpenCDATA);
_data = [];
_event = 0;

Expand All @@ -30,6 +30,7 @@ describe('When parsing XML, the SaxWasm', () => {

it('should report CDATA correctly', () => {
parser.write('<div><![CDATA[ did you know "x < y" & "z > y"? so I guess that means that z > x ]]></div>');
expect(_data[0]).to.be(' did you know "x < y" & "z > y"? so I guess that means that z > x ');
expect(_data[ 0 ]).to.eql({ line: 0, character: 7 });
expect(_data[ 1 ]).to.be(' did you know "x < y" & "z > y"? so I guess that means that z > x ');
});
});
2 changes: 1 addition & 1 deletion src/sax/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> SAXParser<'a> {
self.state = State::Cdata;
self.cdata = String::new();
if self.events & Event::OpenCDATA as u32 != 0 {
let v = [self.line - 7, self.character];
let v = [self.line, self.character - 7];
(self.event_handler)(Event::OpenCDATA as u32, v.as_ptr(), v.len());
}
} else if self.sgml_decl == "--" {
Expand Down

0 comments on commit 28d5956

Please sign in to comment.