Skip to content

Commit

Permalink
fix(xml parser): Handle whitespace around attribute =
Browse files Browse the repository at this point in the history
  • Loading branch information
hdeshev committed Jun 17, 2015
1 parent b4b5b1e commit 2a2c0e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
14 changes: 13 additions & 1 deletion js-libs/easysax/easysax.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ function EasySAXParser() {
continue;
};

if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел
continue;
};


if (w !== 61) { // "=" == 61
//console.log('error 2');
Expand All @@ -272,7 +276,7 @@ function EasySAXParser() {
break;
};

name = s.substring(i, j);
name = s.substring(i, j).trim();
ok = true;

if (name === 'xmlns:xmlns') {
Expand All @@ -282,6 +286,14 @@ function EasySAXParser() {

w = s.charCodeAt(j+1);

while (w = s.charCodeAt(j+1)) {
if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел
j++;
} else {
break;
}
}

if (w === 34) { // '"'
j = s.indexOf('"', i = j+2 );

Expand Down
31 changes: 19 additions & 12 deletions node-tests/test-xml.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import {assert} from "chai";
import {XmlParser, ParserEvent, ParserEventType} from 'xml';
//import xml = require('xml');
import xml = require('xml');

describe("xml parser", () => {
it("parses simple element", () => {
let attributes = null;
let element = null;
let last_element = null;
let last_attrs = null;
let parser = null;

var parser = new XmlParser(function (event: ParserEvent) {
beforeEach(() => {
parser = new xml.XmlParser(function (event: xml.ParserEvent) {
switch (event.eventType) {
case ParserEventType.StartElement:
element = event.elementName;
attributes = event.attributes;
case xml.ParserEventType.StartElement:
last_element = event.elementName;
last_attrs = event.attributes;
break;
}
});
});


parser.parse("<TextField text='hello' />");
it("handles whitespace around attribute =", () => {
let attributes = null;
let element = null;

assert.equal('TextField', element);
assert.equal('hello', attributes['text']);
parser.parse("<TextField text = \n 'hello' />");

assert.equal('TextField', last_element);
assert.equal('hello', last_attrs['text']);
});

});

0 comments on commit 2a2c0e5

Please sign in to comment.