sax 0.5.6 → 0.6.1
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/LICENSE +25 -0
- package/lib/sax.js +86 -4
- package/package.json +1 -1
- package/test/attribute-no-space.js +75 -0
- package/test/emoji.js +12 -0
- package/test/end_empty_stream.js +5 -0
- package/test/flush.js +13 -0
- package/component.json +0 -12
package/LICENSE
CHANGED
|
@@ -30,3 +30,28 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
30
30
|
The file "examples/strict.dtd" is licensed by the W3C and used according
|
|
31
31
|
to the terms of the W3C SOFTWARE NOTICE AND LICENSE. See LICENSE-W3C.html
|
|
32
32
|
for details.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
"String.fromCodePoint" used under the terms of the MIT license. Its license
|
|
36
|
+
follows:
|
|
37
|
+
|
|
38
|
+
Copyright Mathias Bynens <http://mathiasbynens.be/>
|
|
39
|
+
|
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
41
|
+
a copy of this software and associated documentation files (the
|
|
42
|
+
"Software"), to deal in the Software without restriction, including
|
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
46
|
+
the following conditions:
|
|
47
|
+
|
|
48
|
+
The above copyright notice and this permission notice shall be
|
|
49
|
+
included in all copies or substantial portions of the Software.
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
54
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
55
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
56
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
57
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/sax.js
CHANGED
|
@@ -133,11 +133,24 @@ function clearBuffers (parser) {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
function flushBuffers (parser) {
|
|
137
|
+
closeText(parser)
|
|
138
|
+
if (parser.cdata !== "") {
|
|
139
|
+
emitNode(parser, "oncdata", parser.cdata)
|
|
140
|
+
parser.cdata = ""
|
|
141
|
+
}
|
|
142
|
+
if (parser.script !== "") {
|
|
143
|
+
emitNode(parser, "onscript", parser.script)
|
|
144
|
+
parser.script = ""
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
SAXParser.prototype =
|
|
137
149
|
{ end: function () { end(this) }
|
|
138
150
|
, write: write
|
|
139
151
|
, resume: function () { this.error = null; return this }
|
|
140
152
|
, close: function () { return this.write(null) }
|
|
153
|
+
, flush: function () { flushBuffers(this) }
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
try {
|
|
@@ -321,6 +334,7 @@ sax.STATE =
|
|
|
321
334
|
, ATTRIB_NAME_SAW_WHITE : S++ // <a foo _
|
|
322
335
|
, ATTRIB_VALUE : S++ // <a foo=
|
|
323
336
|
, ATTRIB_VALUE_QUOTED : S++ // <a foo="bar
|
|
337
|
+
, ATTRIB_VALUE_CLOSED : S++ // <a foo="bar"
|
|
324
338
|
, ATTRIB_VALUE_UNQUOTED : S++ // <a foo=bar
|
|
325
339
|
, ATTRIB_VALUE_ENTITY_Q : S++ // <foo bar="""
|
|
326
340
|
, ATTRIB_VALUE_ENTITY_U : S++ // <foo bar="
|
|
@@ -633,7 +647,7 @@ function error (parser, er) {
|
|
|
633
647
|
|
|
634
648
|
function end (parser) {
|
|
635
649
|
if (!parser.closedRoot) strictFail(parser, "Unclosed root tag")
|
|
636
|
-
if (parser.state !== S.TEXT) error(parser, "Unexpected end")
|
|
650
|
+
if ((parser.state !== S.BEGIN) && (parser.state !== S.TEXT)) error(parser, "Unexpected end")
|
|
637
651
|
closeText(parser)
|
|
638
652
|
parser.c = ""
|
|
639
653
|
parser.closed = true
|
|
@@ -890,7 +904,8 @@ function parseEntity (parser) {
|
|
|
890
904
|
strictFail(parser, "Invalid character entity")
|
|
891
905
|
return "&"+parser.entity + ";"
|
|
892
906
|
}
|
|
893
|
-
|
|
907
|
+
|
|
908
|
+
return String.fromCodePoint(num)
|
|
894
909
|
}
|
|
895
910
|
|
|
896
911
|
function write (chunk) {
|
|
@@ -1237,7 +1252,20 @@ function write (chunk) {
|
|
|
1237
1252
|
}
|
|
1238
1253
|
attrib(parser)
|
|
1239
1254
|
parser.q = ""
|
|
1240
|
-
parser.state = S.
|
|
1255
|
+
parser.state = S.ATTRIB_VALUE_CLOSED
|
|
1256
|
+
continue
|
|
1257
|
+
|
|
1258
|
+
case S.ATTRIB_VALUE_CLOSED:
|
|
1259
|
+
if (is(whitespace, c)) {
|
|
1260
|
+
parser.state = S.ATTRIB
|
|
1261
|
+
} else if (c === ">") openTag(parser)
|
|
1262
|
+
else if (c === "/") parser.state = S.OPEN_TAG_SLASH
|
|
1263
|
+
else if (is(nameStart, c)) {
|
|
1264
|
+
strictFail(parser, "No whitespace between attributes")
|
|
1265
|
+
parser.attribName = c
|
|
1266
|
+
parser.attribValue = ""
|
|
1267
|
+
parser.state = S.ATTRIB_NAME
|
|
1268
|
+
} else strictFail(parser, "Invalid attribute name")
|
|
1241
1269
|
continue
|
|
1242
1270
|
|
|
1243
1271
|
case S.ATTRIB_VALUE_UNQUOTED:
|
|
@@ -1325,4 +1353,58 @@ function write (chunk) {
|
|
|
1325
1353
|
return parser
|
|
1326
1354
|
}
|
|
1327
1355
|
|
|
1328
|
-
|
|
1356
|
+
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
|
|
1357
|
+
if (!String.fromCodePoint) {
|
|
1358
|
+
(function() {
|
|
1359
|
+
var stringFromCharCode = String.fromCharCode;
|
|
1360
|
+
var floor = Math.floor;
|
|
1361
|
+
var fromCodePoint = function() {
|
|
1362
|
+
var MAX_SIZE = 0x4000;
|
|
1363
|
+
var codeUnits = [];
|
|
1364
|
+
var highSurrogate;
|
|
1365
|
+
var lowSurrogate;
|
|
1366
|
+
var index = -1;
|
|
1367
|
+
var length = arguments.length;
|
|
1368
|
+
if (!length) {
|
|
1369
|
+
return '';
|
|
1370
|
+
}
|
|
1371
|
+
var result = '';
|
|
1372
|
+
while (++index < length) {
|
|
1373
|
+
var codePoint = Number(arguments[index]);
|
|
1374
|
+
if (
|
|
1375
|
+
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
|
1376
|
+
codePoint < 0 || // not a valid Unicode code point
|
|
1377
|
+
codePoint > 0x10FFFF || // not a valid Unicode code point
|
|
1378
|
+
floor(codePoint) != codePoint // not an integer
|
|
1379
|
+
) {
|
|
1380
|
+
throw RangeError('Invalid code point: ' + codePoint);
|
|
1381
|
+
}
|
|
1382
|
+
if (codePoint <= 0xFFFF) { // BMP code point
|
|
1383
|
+
codeUnits.push(codePoint);
|
|
1384
|
+
} else { // Astral code point; split in surrogate halves
|
|
1385
|
+
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
1386
|
+
codePoint -= 0x10000;
|
|
1387
|
+
highSurrogate = (codePoint >> 10) + 0xD800;
|
|
1388
|
+
lowSurrogate = (codePoint % 0x400) + 0xDC00;
|
|
1389
|
+
codeUnits.push(highSurrogate, lowSurrogate);
|
|
1390
|
+
}
|
|
1391
|
+
if (index + 1 == length || codeUnits.length > MAX_SIZE) {
|
|
1392
|
+
result += stringFromCharCode.apply(null, codeUnits);
|
|
1393
|
+
codeUnits.length = 0;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return result;
|
|
1397
|
+
};
|
|
1398
|
+
if (Object.defineProperty) {
|
|
1399
|
+
Object.defineProperty(String, 'fromCodePoint', {
|
|
1400
|
+
'value': fromCodePoint,
|
|
1401
|
+
'configurable': true,
|
|
1402
|
+
'writable': true
|
|
1403
|
+
});
|
|
1404
|
+
} else {
|
|
1405
|
+
String.fromCodePoint = fromCodePoint;
|
|
1406
|
+
}
|
|
1407
|
+
}());
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
})(typeof exports === "undefined" ? sax = {} : exports);
|
package/package.json
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// non-strict: no error
|
|
2
|
+
require(__dirname).test
|
|
3
|
+
( { xml : '<root attr1="first"attr2="second"/>'
|
|
4
|
+
|
|
5
|
+
, expect :
|
|
6
|
+
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
7
|
+
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
8
|
+
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
9
|
+
, [ "closetag", "root" ]
|
|
10
|
+
]
|
|
11
|
+
, strict : false
|
|
12
|
+
, opt : { lowercase: true }
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// strict: should give an error, but still parse
|
|
17
|
+
require(__dirname).test
|
|
18
|
+
( { xml : '<root attr1="first"attr2="second"/>'
|
|
19
|
+
|
|
20
|
+
, expect :
|
|
21
|
+
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
22
|
+
, [ "error", "No whitespace between attributes\nLine: 0\nColumn: 20\nChar: a" ]
|
|
23
|
+
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
24
|
+
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
25
|
+
, [ "closetag", "root" ]
|
|
26
|
+
]
|
|
27
|
+
, strict : true
|
|
28
|
+
, opt : { }
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
// strict: other cases should still pass
|
|
33
|
+
require(__dirname).test
|
|
34
|
+
( { xml : '<root attr1="first" attr2="second"/>'
|
|
35
|
+
|
|
36
|
+
, expect :
|
|
37
|
+
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
38
|
+
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
39
|
+
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
40
|
+
, [ "closetag", "root" ]
|
|
41
|
+
]
|
|
42
|
+
, strict : true
|
|
43
|
+
, opt : { }
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
// strict: other cases should still pass
|
|
48
|
+
require(__dirname).test
|
|
49
|
+
( { xml : '<root attr1="first"\nattr2="second"/>'
|
|
50
|
+
|
|
51
|
+
, expect :
|
|
52
|
+
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
53
|
+
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
54
|
+
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
55
|
+
, [ "closetag", "root" ]
|
|
56
|
+
]
|
|
57
|
+
, strict : true
|
|
58
|
+
, opt : { }
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
// strict: other cases should still pass
|
|
63
|
+
require(__dirname).test
|
|
64
|
+
( { xml : '<root attr1="first" attr2="second"/>'
|
|
65
|
+
|
|
66
|
+
, expect :
|
|
67
|
+
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
68
|
+
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
69
|
+
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
70
|
+
, [ "closetag", "root" ]
|
|
71
|
+
]
|
|
72
|
+
, strict : true
|
|
73
|
+
, opt : { }
|
|
74
|
+
}
|
|
75
|
+
)
|
package/test/emoji.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// split high-order numeric attributes into surrogate pairs
|
|
2
|
+
require(__dirname).test
|
|
3
|
+
( { xml : '<a>🔥</a>'
|
|
4
|
+
, expect :
|
|
5
|
+
[ [ 'opentag', { name: 'A', attributes: {}, isSelfClosing: false } ]
|
|
6
|
+
, [ 'text', '\ud83d\udd25' ]
|
|
7
|
+
, [ 'closetag', 'A' ]
|
|
8
|
+
]
|
|
9
|
+
, strict : false
|
|
10
|
+
, opt : {}
|
|
11
|
+
}
|
|
12
|
+
)
|
package/test/flush.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var parser = require(__dirname).test({
|
|
2
|
+
expect: [
|
|
3
|
+
['opentag', {'name':'T', attributes:{}, isSelfClosing: false}],
|
|
4
|
+
['text', 'flush'],
|
|
5
|
+
['text', 'rest'],
|
|
6
|
+
['closetag', 'T'],
|
|
7
|
+
]
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
parser.write('<T>flush');
|
|
11
|
+
parser.flush();
|
|
12
|
+
parser.write('rest</T>');
|
|
13
|
+
parser.close();
|
package/component.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sax",
|
|
3
|
-
"description": "An evented streaming XML parser in JavaScript",
|
|
4
|
-
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
|
5
|
-
"version": "0.5.2",
|
|
6
|
-
"main": "lib/sax.js",
|
|
7
|
-
"license": "BSD",
|
|
8
|
-
"scripts": [
|
|
9
|
-
"lib/sax.js"
|
|
10
|
-
],
|
|
11
|
-
"repository": "git://github.com/isaacs/sax-js.git"
|
|
12
|
-
}
|