diff --git a/examples/example.js b/examples/example.js index 152ba44a..cf083ef3 100644 --- a/examples/example.js +++ b/examples/example.js @@ -2,27 +2,29 @@ var fs = require('fs'), util = require('util'), path = require('path'), xml = fs.readFileSync(path.join(__dirname, 'test.xml'), 'utf8'), - sax = require('../lib/sax'), - strict = sax.parser(true), - loose = sax.parser(false, {trim: true}), + saxes = require('../lib/saxes'), + parser = saxes.parser(), inspector = function (ev) { return function (data) { - console.error('%s %s %j', this.line + ':' + this.column, ev, data) - }} + console.error('%s %s %j', this.line + ':' + this.column, ev, data) + if (ev === "error") { + parser.resume() + } + }} -sax.EVENTS.forEach(function (ev) { - loose['on' + ev] = inspector(ev) +saxes.EVENTS.forEach(function (ev) { + parser['on' + ev] = inspector(ev) }) -loose.onend = function () { +parser.onend = function () { console.error('end') - console.error(loose) + console.error(parser) } // do this in random bits at a time to verify that it works. (function () { if (xml) { var c = Math.ceil(Math.random() * 1000) - loose.write(xml.substr(0, c)) + parser.write(xml.substr(0, c)) xml = xml.substr(c) process.nextTick(arguments.callee) - } else loose.close() -})() + } else parser.close() +}()) diff --git a/lib/saxes.js b/lib/saxes.js index 795d607e..8fe80908 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -1,5 +1,5 @@ ;(function (sax) { // wrapper for non-node envs - sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } + sax.parser = function (opt) { return new SAXParser(opt) } sax.SAXParser = SAXParser sax.SAXStream = SAXStream sax.createStream = createStream @@ -18,7 +18,7 @@ var buffers = [ 'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', - 'attribValue', 'cdata', 'script' + 'attribValue', 'cdata' ] sax.EVENTS = [ @@ -37,14 +37,13 @@ 'error', 'end', 'ready', - 'script', 'opennamespace', 'closenamespace' ] - function SAXParser (strict, opt) { + function SAXParser (opt) { if (!(this instanceof SAXParser)) { - return new SAXParser(strict, opt) + return new SAXParser(opt) } var parser = this @@ -57,8 +56,6 @@ parser.tags = [] parser.closed = parser.closedRoot = parser.sawRoot = false parser.tag = parser.error = null - parser.strict = !!strict - parser.noscript = !!(strict || parser.opt.noscript) parser.state = S.BEGIN parser.strictEntities = parser.opt.strictEntities parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES) @@ -116,11 +113,6 @@ parser.cdata = '' break - case 'script': - emitNode(parser, 'onscript', parser.script) - parser.script = '' - break - default: error(parser, 'Max buffer length exceeded: ' + buffers[i]) } @@ -144,10 +136,6 @@ emitNode(parser, 'oncdata', parser.cdata) parser.cdata = '' } - if (parser.script !== '') { - emitNode(parser, 'onscript', parser.script) - parser.script = '' - } } SAXParser.prototype = { @@ -169,18 +157,18 @@ return ev !== 'error' && ev !== 'end' }) - function createStream (strict, opt) { - return new SAXStream(strict, opt) + function createStream (opt) { + return new SAXStream(opt) } - function SAXStream (strict, opt) { + function SAXStream (opt) { if (!(this instanceof SAXStream)) { - return new SAXStream(strict, opt) + return new SAXStream(opt) } Stream.apply(this) - this._parser = new SAXParser(strict, opt) + this._parser = new SAXParser(opt) this.writable = true this.readable = true @@ -339,8 +327,6 @@ ATTRIB_VALUE_ENTITY_U: S++, // - SCRIPT: S++, // ", - expect: [ - ['opentagstart', {'name': 'HTML', 'attributes': {}}], - ['opentag', {'name': 'HTML', 'attributes': {}, isSelfClosing: false}], - ['opentagstart', {'name': 'HEAD', 'attributes': {}}], - ['opentag', {'name': 'HEAD', 'attributes': {}, isSelfClosing: false}], - ['opentagstart', {'name': 'SCRIPT', 'attributes': {}}], - ['opentag', {'name': 'SCRIPT', 'attributes': {}, isSelfClosing: false}], - ['script', "'
foo
", - expect: [ - [ - 'opentagstart', - { - 'name': 'HTML', - 'attributes': {} - } - ], - [ - 'opentag', - { - 'name': 'HTML', - 'attributes': {}, - 'isSelfClosing': false - } - ], - [ - 'opentagstart', - { - 'name': 'HEAD', - 'attributes': {} - } - ], - [ - 'opentag', - { - 'name': 'HEAD', - 'attributes': {}, - 'isSelfClosing': false - } - ], - [ - 'opentagstart', - { - 'name': 'SCRIPT', - 'attributes': {} - } - ], - [ - 'opentag', - { - 'name': 'SCRIPT', - 'attributes': {}, - 'isSelfClosing': false - } - ], - [ - 'script', - "if (1 < 0) { console.log('elo there'); }" - ], - [ - 'closetag', - 'SCRIPT' - ], - [ - 'closetag', - 'HEAD' - ], - [ - 'closetag', - 'HTML' - ] - ] -}) diff --git a/test/self-closing-child-strict.js b/test/self-closing-child-strict.js deleted file mode 100644 index 359670af..00000000 --- a/test/self-closing-child-strict.js +++ /dev/null @@ -1,57 +0,0 @@ -require(__dirname).test({ - xml: '' + - '' + - '' + - '' + - '' + - '=(|)' + - '' + - '', - expect: [ - ['opentagstart', { - 'name': 'root', - 'attributes': {} - }], - ['opentag', { - 'name': 'root', - 'attributes': {}, - 'isSelfClosing': false - }], - ['opentagstart', { - 'name': 'child', - 'attributes': {} - }], - ['opentag', { - 'name': 'child', - 'attributes': {}, - 'isSelfClosing': false - }], - ['opentagstart', { - 'name': 'haha', - 'attributes': {} - }], - ['opentag', { - 'name': 'haha', - 'attributes': {}, - 'isSelfClosing': true - }], - ['closetag', 'haha'], - ['closetag', 'child'], - ['opentagstart', { - 'name': 'monkey', - 'attributes': {} - }], - ['opentag', { - 'name': 'monkey', - 'attributes': {}, - 'isSelfClosing': false - }], - ['text', '=(|)'], - ['closetag', 'monkey'], - ['closetag', 'root'], - ['end'], - ['ready'] - ], - strict: true, - opt: {} -}) diff --git a/test/self-closing-child.js b/test/self-closing-child.js index e24a17ba..e6e34cfd 100644 --- a/test/self-closing-child.js +++ b/test/self-closing-child.js @@ -9,49 +9,48 @@ require(__dirname).test({ '', expect: [ ['opentagstart', { - 'name': 'ROOT', + 'name': 'root', 'attributes': {} }], ['opentag', { - 'name': 'ROOT', + 'name': 'root', 'attributes': {}, 'isSelfClosing': false }], ['opentagstart', { - 'name': 'CHILD', + 'name': 'child', 'attributes': {} }], ['opentag', { - 'name': 'CHILD', + 'name': 'child', 'attributes': {}, 'isSelfClosing': false }], ['opentagstart', { - 'name': 'HAHA', + 'name': 'haha', 'attributes': {} }], ['opentag', { - 'name': 'HAHA', + 'name': 'haha', 'attributes': {}, 'isSelfClosing': true }], - ['closetag', 'HAHA'], - ['closetag', 'CHILD'], + ['closetag', 'haha'], + ['closetag', 'child'], ['opentagstart', { - 'name': 'MONKEY', + 'name': 'monkey', 'attributes': {} }], ['opentag', { - 'name': 'MONKEY', + 'name': 'monkey', 'attributes': {}, 'isSelfClosing': false }], ['text', '=(|)'], - ['closetag', 'MONKEY'], - ['closetag', 'ROOT'], + ['closetag', 'monkey'], + ['closetag', 'root'], ['end'], ['ready'] ], - strict: false, opt: {} }) diff --git a/test/self-closing-tag.js b/test/self-closing-tag.js index 4e1bd7df..72839971 100644 --- a/test/self-closing-tag.js +++ b/test/self-closing-tag.js @@ -7,21 +7,21 @@ require(__dirname).test({ '' + ' ', expect: [ - ['opentagstart', {name: 'ROOT', attributes: {}}], - ['opentag', {name: 'ROOT', attributes: {}, isSelfClosing: false}], - ['opentagstart', {name: 'HAHA', attributes: {}}], - ['opentag', {name: 'HAHA', attributes: {}, isSelfClosing: true}], - ['closetag', 'HAHA'], - ['opentagstart', {name: 'HAHA', attributes: {}}], - ['opentag', {name: 'HAHA', attributes: {}, isSelfClosing: true}], - ['closetag', 'HAHA'], - // ["opentag", {name:"HAHA", attributes:{}}], - // ["closetag", "HAHA"], - ['opentagstart', {name: 'MONKEY', attributes: {}}], - ['opentag', {name: 'MONKEY', attributes: {}, isSelfClosing: false}], + ['opentagstart', {name: 'root', attributes: {}}], + ['opentag', {name: 'root', attributes: {}, isSelfClosing: false}], + ['opentagstart', {name: 'haha', attributes: {}}], + ['opentag', {name: 'haha', attributes: {}, isSelfClosing: true}], + ['closetag', 'haha'], + ['opentagstart', {name: 'haha', attributes: {}}], + ['opentag', {name: 'haha', attributes: {}, isSelfClosing: true}], + ['closetag', 'haha'], + // ["opentag", {name:"haha", attributes:{}}], + // ["closetag", "haha"], + ['opentagstart', {name: 'monkey', attributes: {}}], + ['opentag', {name: 'monkey', attributes: {}, isSelfClosing: false}], ['text', '=(|)'], - ['closetag', 'MONKEY'], - ['closetag', 'ROOT'] + ['closetag', 'monkey'], + ['closetag', 'root'] ], opt: { trim: true } }) diff --git a/test/stand-alone-comment.js b/test/stand-alone-comment.js index a13a8b03..207b4f63 100644 --- a/test/stand-alone-comment.js +++ b/test/stand-alone-comment.js @@ -7,6 +7,5 @@ require(__dirname).test({ ' stand alone comment ' ] ], - strict: true, opt: {} }) diff --git a/test/stray-ending.js b/test/stray-ending.js deleted file mode 100644 index 2577c481..00000000 --- a/test/stray-ending.js +++ /dev/null @@ -1,51 +0,0 @@ -// stray ending tags should just be ignored in non-strict mode. -// https://github.com/isaacs/sax-js/issues/32 -require(__dirname).test({ - xml: '', - expect: [ - [ - 'opentagstart', - { - name: 'A', - attributes: {} - } - ], - [ - 'opentag', - { - name: 'A', - attributes: {}, - isSelfClosing: false - } - ], - [ - 'opentagstart', - { - name: 'B', - attributes: {} - } - ], - [ - 'opentag', - { - name: 'B', - attributes: {}, - isSelfClosing: false - } - ], - [ - 'text', - '' - ], - [ - 'closetag', - 'B' - ], - [ - 'closetag', - 'A' - ] - ], - strict: false, - opt: {} -}) diff --git a/test/trailing-attribute-no-value.js b/test/trailing-attribute-no-value.js index e6403225..1a8ce7aa 100644 --- a/test/trailing-attribute-no-value.js +++ b/test/trailing-attribute-no-value.js @@ -1,9 +1,14 @@ require(__dirname).test({ - xml: '', + xml: '', expect: [ - ['opentagstart', {name: 'ROOT', attributes: {}}], - ['attribute', {name: 'ATTRIB', value: 'attrib'}], - ['opentag', {name: 'ROOT', attributes: {'ATTRIB': 'attrib'}, isSelfClosing: false}] + ['opentagstart', {name: 'root', attributes: {}}], + ['error', 'Attribute without value\n\ +Line: 0\n\ +Column: 13\n\ +Char: >'], + ['attribute', {name: 'attrib', value: 'attrib'}], + ['opentag', {name: 'root', attributes: {'attrib': 'attrib'}, isSelfClosing: false}], + ['closetag', 'root'], ], opt: { trim: true } }) diff --git a/test/trailing-non-whitespace.js b/test/trailing-non-whitespace.js index 8212d6ce..0e4876d6 100644 --- a/test/trailing-non-whitespace.js +++ b/test/trailing-non-whitespace.js @@ -2,20 +2,34 @@ require(__dirname).test({ xml: 'Welcome, to monkey land', expect: [ ['opentagstart', { - 'name': 'SPAN', + 'name': 'span', 'attributes': {} }], ['opentag', { - 'name': 'SPAN', + 'name': 'span', 'attributes': {}, isSelfClosing: false }], ['text', 'Welcome,'], - ['closetag', 'SPAN'], - ['text', ' to monkey land'], + ['closetag', 'span'], + ['text', ' '], + ['error', 'Text data outside of root node.\n\ +Line: 0\n\ +Column: 23\n\ +Char: t'], + ['text', 't'], + ['error', 'Text data outside of root node.\n\ +Line: 0\n\ +Column: 24\n\ +Char: o'], + ['text', 'o '], + ['error', 'Text data outside of root node.\n\ +Line: 0\n\ +Column: 26\n\ +Char: m'], + ['text', 'm'], ['end'], ['ready'] ], - strict: false, opt: {} }) diff --git a/test/unclosed-root.js b/test/unclosed-root.js index dbd1178a..58951f9a 100644 --- a/test/unclosed-root.js +++ b/test/unclosed-root.js @@ -21,6 +21,5 @@ require(__dirname).test({ 'Unclosed root tag\nLine: 0\nColumn: 6\nChar: ' ] ], - strict: true, opt: {} }) diff --git a/test/unquoted.js b/test/unquoted.js deleted file mode 100644 index 4bbd511c..00000000 --- a/test/unquoted.js +++ /dev/null @@ -1,45 +0,0 @@ -// unquoted attributes should be ok in non-strict mode -// https://github.com/isaacs/sax-js/issues/31 -require(__dirname).test({ - xml: '', - expect: [ - [ - 'opentagstart', - { - name: 'SPAN', - attributes: {} - } - ], - [ - 'attribute', - { - name: 'CLASS', - value: 'test' - } - ], - [ - 'attribute', - { - name: 'HELLO', - value: 'world' - } - ], - [ - 'opentag', - { - name: 'SPAN', - attributes: { - CLASS: 'test', - HELLO: 'world' - }, - isSelfClosing: false - } - ], - [ - 'closetag', - 'SPAN' - ] - ], - strict: false, - opt: {} -}) diff --git a/test/utf8-split.js b/test/utf8-split.js index a4b1df1e..f917800f 100644 --- a/test/utf8-split.js +++ b/test/utf8-split.js @@ -30,5 +30,5 @@ saxesStream2.write(new Buffer('')) saxesStream2.write(new Buffer([0xC0])) saxesStream2.write(new Buffer('')) saxesStream2.write(Buffer.concat([new Buffer(''), b.slice(0, 1)])) -saxesStream2.write(new Buffer('')) +saxesStream2.write(new Buffer('')) saxesStream2.end() diff --git a/test/xml-internal-entities.js b/test/xml-internal-entities.js index 3c49e500..6d444e1c 100644 --- a/test/xml-internal-entities.js +++ b/test/xml-internal-entities.js @@ -81,7 +81,6 @@ iExpect.push([ iExpect.push([ 'closetag', 'a' ]) var parser = require(__dirname).test({ - strict: true, expect: iExpect }) diff --git a/test/xml_entities.js b/test/xml_entities.js deleted file mode 100644 index 3d739d0d..00000000 --- a/test/xml_entities.js +++ /dev/null @@ -1,12 +0,0 @@ -require(__dirname).test({ - opt: { strictEntities: true }, - xml: '⌋ ' + - '♠ © → & ' + - '< < < < < > ℜ ℘ €', - expect: [ - ['opentagstart', {'name': 'R', attributes: {}}], - ['opentag', {'name': 'R', attributes: {}, isSelfClosing: false}], - ['text', '⌋ ♠ © → & < < < < < > ℜ ℘ €'], - ['closetag', 'R'] - ] -}) diff --git a/test/xmlns-as-tag-name.js b/test/xmlns-as-tag-name.js index 18cd44d6..db10ecc6 100644 --- a/test/xmlns-as-tag-name.js +++ b/test/xmlns-as-tag-name.js @@ -26,7 +26,6 @@ require(__dirname).test({ 'xmlns' ] ], - strict: true, opt: { xmlns: true } diff --git a/test/xmlns-issue-41.js b/test/xmlns-issue-41.js index 435b7e6c..e526c234 100644 --- a/test/xmlns-issue-41.js +++ b/test/xmlns-issue-41.js @@ -85,7 +85,6 @@ xmls.forEach(function (x, i) { t.test({ xml: x, expect: expected[i], - strict: true, opt: { xmlns: true } diff --git a/test/xmlns-rebinding.js b/test/xmlns-rebinding.js index 8086b447..78579c0c 100644 --- a/test/xmlns-rebinding.js +++ b/test/xmlns-rebinding.js @@ -320,7 +320,6 @@ require(__dirname).test({ } ] ], - strict: true, opt: { xmlns: true } diff --git a/test/xmlns-strict.js b/test/xmlns-strict.js index 87d26c44..79f37079 100644 --- a/test/xmlns-strict.js +++ b/test/xmlns-strict.js @@ -327,7 +327,6 @@ require(__dirname).test({ 'root' ] ], - strict: true, opt: { xmlns: true } diff --git a/test/xmlns-unbound-element.js b/test/xmlns-unbound-element.js index 60759b1d..422763ad 100644 --- a/test/xmlns-unbound-element.js +++ b/test/xmlns-unbound-element.js @@ -1,5 +1,4 @@ require(__dirname).test({ - strict: true, opt: { xmlns: true }, expect: [ [ @@ -34,7 +33,6 @@ require(__dirname).test({ }).write('') require(__dirname).test({ - strict: true, opt: { xmlns: true }, diff --git a/test/xmlns-unbound.js b/test/xmlns-unbound.js index 319d3504..76159fc8 100644 --- a/test/xmlns-unbound.js +++ b/test/xmlns-unbound.js @@ -1,5 +1,4 @@ require(__dirname).test({ - strict: true, opt: { xmlns: true }, expect: [ [ diff --git a/test/xmlns-xml-default-ns.js b/test/xmlns-xml-default-ns.js index 41d55720..321f0894 100644 --- a/test/xmlns-xml-default-ns.js +++ b/test/xmlns-xml-default-ns.js @@ -64,7 +64,6 @@ require(__dirname).test({ } ] ], - strict: true, opt: { xmlns: true } diff --git a/test/xmlns-xml-default-prefix-attribute.js b/test/xmlns-xml-default-prefix-attribute.js index 51cfbb6f..6750b191 100644 --- a/test/xmlns-xml-default-prefix-attribute.js +++ b/test/xmlns-xml-default-prefix-attribute.js @@ -44,6 +44,5 @@ require(__dirname).test({ 'root' ] ], - strict: true, opt: { xmlns: true } }) diff --git a/test/xmlns-xml-default-prefix.js b/test/xmlns-xml-default-prefix.js index fd48cbdd..dfd210a8 100644 --- a/test/xmlns-xml-default-prefix.js +++ b/test/xmlns-xml-default-prefix.js @@ -26,6 +26,5 @@ require(__dirname).test({ 'xml:root' ] ], - strict: true, opt: { xmlns: true } }) diff --git a/test/xmlns-xml-default-redefine.js b/test/xmlns-xml-default-redefine.js index 2a8f7050..da6c30e3 100644 --- a/test/xmlns-xml-default-redefine.js +++ b/test/xmlns-xml-default-redefine.js @@ -50,6 +50,5 @@ require(__dirname).test({ 'xml:root' ] ], - strict: true, opt: { xmlns: true } })