| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,6 +263,10 @@ function EasySAXParser() { | |||
| 263 | 263 | continue; | |
| 264 | 264 | }; | |
| 265 | 265 | ||
| 266 | + if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел | ||
| 267 | + continue; | ||
| 268 | + }; | ||
| 269 | + | ||
| 266 | 270 | ||
| 267 | 271 | if (w !== 61) { // "=" == 61 | |
| 268 | 272 | //console.log('error 2'); | |
@@ -272,7 +276,7 @@ function EasySAXParser() { | |||
| 272 | 276 | break; | |
| 273 | 277 | }; | |
| 274 | 278 | ||
| 275 | - name = s.substring(i, j); | ||
| 279 | + name = s.substring(i, j).trim(); | ||
| 276 | 280 | ok = true; | |
| 277 | 281 | ||
| 278 | 282 | if (name === 'xmlns:xmlns') { | |
@@ -282,6 +286,14 @@ function EasySAXParser() { | |||
| 282 | 286 | ||
| 283 | 287 | w = s.charCodeAt(j+1); | |
| 284 | 288 | ||
| 289 | + while (w = s.charCodeAt(j+1)) { | ||
| 290 | + if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел | ||
| 291 | + j++; | ||
| 292 | + } else { | ||
| 293 | + break; | ||
| 294 | + } | ||
| 295 | + } | ||
| 296 | + | ||
| 285 | 297 | if (w === 34) { // '"' | |
| 286 | 298 | j = s.indexOf('"', i = j+2 ); | |
| 287 | 299 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,24 +1,31 @@ | |||
| 1 | 1 | import {assert} from "chai"; | |
| 2 | - import {XmlParser, ParserEvent, ParserEventType} from 'xml'; | ||
| 3 | - //import xml = require('xml'); | ||
| 2 | + import xml = require('xml'); | ||
| 4 | 3 | ||
| 5 | 4 | describe("xml parser", () => { | |
| 6 | - it("parses simple element", () => { | ||
| 7 | - let attributes = null; | ||
| 8 | - let element = null; | ||
| 5 | + let last_element = null; | ||
| 6 | + let last_attrs = null; | ||
| 7 | + let parser = null; | ||
| 9 | 8 | ||
| 10 | - var parser = new XmlParser(function (event: ParserEvent) { | ||
| 9 | + beforeEach(() => { | ||
| 10 | + parser = new xml.XmlParser(function (event: xml.ParserEvent) { | ||
| 11 | 11 | switch (event.eventType) { | |
| 12 | - case ParserEventType.StartElement: | ||
| 13 | - element = event.elementName; | ||
| 14 | - attributes = event.attributes; | ||
| 12 | + case xml.ParserEventType.StartElement: | ||
| 13 | + last_element = event.elementName; | ||
| 14 | + last_attrs = event.attributes; | ||
| 15 | 15 | break; | |
| 16 | 16 | } | |
| 17 | 17 | }); | |
| 18 | + }); | ||
| 19 | + | ||
| 18 | 20 | ||
| 19 | - parser.parse("<TextField text='hello' />"); | ||
| 21 | + it("handles whitespace around attribute =", () => { | ||
| 22 | + let attributes = null; | ||
| 23 | + let element = null; | ||
| 20 | 24 | ||
| 21 | - assert.equal('TextField', element); | ||
| 22 | - assert.equal('hello', attributes['text']); | ||
| 25 | + parser.parse("<TextField text = \n 'hello' />"); | ||
| 26 | + | ||
| 27 | + assert.equal('TextField', last_element); | ||
| 28 | + assert.equal('hello', last_attrs['text']); | ||
| 23 | 29 | }); | |
| 30 | + | ||
| 24 | 31 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments