sax 1.4.1 → 1.4.2
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.md +55 -0
- package/README.md +42 -43
- package/lib/sax.js +456 -361
- package/package.json +8 -9
- package/LICENSE +0 -41
package/lib/sax.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
;(function (sax) {
|
|
2
|
-
|
|
1
|
+
;(function (sax) {
|
|
2
|
+
// wrapper for non-node envs
|
|
3
|
+
sax.parser = function (strict, opt) {
|
|
4
|
+
return new SAXParser(strict, opt)
|
|
5
|
+
}
|
|
3
6
|
sax.SAXParser = SAXParser
|
|
4
7
|
sax.SAXStream = SAXStream
|
|
5
8
|
sax.createStream = createStream
|
|
@@ -16,9 +19,18 @@
|
|
|
16
19
|
sax.MAX_BUFFER_LENGTH = 64 * 1024
|
|
17
20
|
|
|
18
21
|
var buffers = [
|
|
19
|
-
'comment',
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
+
'comment',
|
|
23
|
+
'sgmlDecl',
|
|
24
|
+
'textNode',
|
|
25
|
+
'tagName',
|
|
26
|
+
'doctype',
|
|
27
|
+
'procInstName',
|
|
28
|
+
'procInstBody',
|
|
29
|
+
'entity',
|
|
30
|
+
'attribName',
|
|
31
|
+
'attribValue',
|
|
32
|
+
'cdata',
|
|
33
|
+
'script',
|
|
22
34
|
]
|
|
23
35
|
|
|
24
36
|
sax.EVENTS = [
|
|
@@ -39,10 +51,10 @@
|
|
|
39
51
|
'ready',
|
|
40
52
|
'script',
|
|
41
53
|
'opennamespace',
|
|
42
|
-
'closenamespace'
|
|
54
|
+
'closenamespace',
|
|
43
55
|
]
|
|
44
56
|
|
|
45
|
-
function SAXParser
|
|
57
|
+
function SAXParser(strict, opt) {
|
|
46
58
|
if (!(this instanceof SAXParser)) {
|
|
47
59
|
return new SAXParser(strict, opt)
|
|
48
60
|
}
|
|
@@ -61,7 +73,10 @@
|
|
|
61
73
|
parser.noscript = !!(strict || parser.opt.noscript)
|
|
62
74
|
parser.state = S.BEGIN
|
|
63
75
|
parser.strictEntities = parser.opt.strictEntities
|
|
64
|
-
parser.ENTITIES =
|
|
76
|
+
parser.ENTITIES =
|
|
77
|
+
parser.strictEntities ?
|
|
78
|
+
Object.create(sax.XML_ENTITIES)
|
|
79
|
+
: Object.create(sax.ENTITIES)
|
|
65
80
|
parser.attribList = []
|
|
66
81
|
|
|
67
82
|
// namespaces form a prototype chain.
|
|
@@ -74,7 +89,7 @@
|
|
|
74
89
|
// disallow unquoted attribute values if not otherwise configured
|
|
75
90
|
// and strict mode is true
|
|
76
91
|
if (parser.opt.unquotedAttributeValues === undefined) {
|
|
77
|
-
parser.opt.unquotedAttributeValues = !strict
|
|
92
|
+
parser.opt.unquotedAttributeValues = !strict
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
// mostly just for error reporting
|
|
@@ -87,7 +102,7 @@
|
|
|
87
102
|
|
|
88
103
|
if (!Object.create) {
|
|
89
104
|
Object.create = function (o) {
|
|
90
|
-
function F
|
|
105
|
+
function F() {}
|
|
91
106
|
F.prototype = o
|
|
92
107
|
var newf = new F()
|
|
93
108
|
return newf
|
|
@@ -102,7 +117,7 @@
|
|
|
102
117
|
}
|
|
103
118
|
}
|
|
104
119
|
|
|
105
|
-
function checkBufferLength
|
|
120
|
+
function checkBufferLength(parser) {
|
|
106
121
|
var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)
|
|
107
122
|
var maxActual = 0
|
|
108
123
|
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
@@ -138,13 +153,13 @@
|
|
|
138
153
|
parser.bufferCheckPosition = m + parser.position
|
|
139
154
|
}
|
|
140
155
|
|
|
141
|
-
function clearBuffers
|
|
156
|
+
function clearBuffers(parser) {
|
|
142
157
|
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
143
158
|
parser[buffers[i]] = ''
|
|
144
159
|
}
|
|
145
160
|
}
|
|
146
161
|
|
|
147
|
-
function flushBuffers
|
|
162
|
+
function flushBuffers(parser) {
|
|
148
163
|
closeText(parser)
|
|
149
164
|
if (parser.cdata !== '') {
|
|
150
165
|
emitNode(parser, 'oncdata', parser.cdata)
|
|
@@ -157,11 +172,20 @@
|
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
SAXParser.prototype = {
|
|
160
|
-
end: function () {
|
|
175
|
+
end: function () {
|
|
176
|
+
end(this)
|
|
177
|
+
},
|
|
161
178
|
write: write,
|
|
162
|
-
resume: function () {
|
|
163
|
-
|
|
164
|
-
|
|
179
|
+
resume: function () {
|
|
180
|
+
this.error = null
|
|
181
|
+
return this
|
|
182
|
+
},
|
|
183
|
+
close: function () {
|
|
184
|
+
return this.write(null)
|
|
185
|
+
},
|
|
186
|
+
flush: function () {
|
|
187
|
+
flushBuffers(this)
|
|
188
|
+
},
|
|
165
189
|
}
|
|
166
190
|
|
|
167
191
|
var Stream
|
|
@@ -176,11 +200,11 @@
|
|
|
176
200
|
return ev !== 'error' && ev !== 'end'
|
|
177
201
|
})
|
|
178
202
|
|
|
179
|
-
function createStream
|
|
203
|
+
function createStream(strict, opt) {
|
|
180
204
|
return new SAXStream(strict, opt)
|
|
181
205
|
}
|
|
182
206
|
|
|
183
|
-
function SAXStream
|
|
207
|
+
function SAXStream(strict, opt) {
|
|
184
208
|
if (!(this instanceof SAXStream)) {
|
|
185
209
|
return new SAXStream(strict, opt)
|
|
186
210
|
}
|
|
@@ -221,21 +245,23 @@
|
|
|
221
245
|
me.on(ev, h)
|
|
222
246
|
},
|
|
223
247
|
enumerable: true,
|
|
224
|
-
configurable: false
|
|
248
|
+
configurable: false,
|
|
225
249
|
})
|
|
226
250
|
})
|
|
227
251
|
}
|
|
228
252
|
|
|
229
253
|
SAXStream.prototype = Object.create(Stream.prototype, {
|
|
230
254
|
constructor: {
|
|
231
|
-
value: SAXStream
|
|
232
|
-
}
|
|
255
|
+
value: SAXStream,
|
|
256
|
+
},
|
|
233
257
|
})
|
|
234
258
|
|
|
235
259
|
SAXStream.prototype.write = function (data) {
|
|
236
|
-
if (
|
|
260
|
+
if (
|
|
261
|
+
typeof Buffer === 'function' &&
|
|
237
262
|
typeof Buffer.isBuffer === 'function' &&
|
|
238
|
-
Buffer.isBuffer(data)
|
|
263
|
+
Buffer.isBuffer(data)
|
|
264
|
+
) {
|
|
239
265
|
if (!this._decoder) {
|
|
240
266
|
var SD = require('string_decoder').StringDecoder
|
|
241
267
|
this._decoder = new SD('utf8')
|
|
@@ -260,7 +286,10 @@
|
|
|
260
286
|
var me = this
|
|
261
287
|
if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) {
|
|
262
288
|
me._parser['on' + ev] = function () {
|
|
263
|
-
var args =
|
|
289
|
+
var args =
|
|
290
|
+
arguments.length === 1 ?
|
|
291
|
+
[arguments[0]]
|
|
292
|
+
: Array.apply(null, arguments)
|
|
264
293
|
args.splice(0, 0, ev)
|
|
265
294
|
me.emit.apply(me, args)
|
|
266
295
|
}
|
|
@@ -283,30 +312,34 @@
|
|
|
283
312
|
// without a significant breaking change to either this parser, or the
|
|
284
313
|
// JavaScript language. Implementation of an emoji-capable xml parser
|
|
285
314
|
// is left as an exercise for the reader.
|
|
286
|
-
var nameStart =
|
|
315
|
+
var nameStart =
|
|
316
|
+
/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/
|
|
287
317
|
|
|
288
|
-
var nameBody =
|
|
318
|
+
var nameBody =
|
|
319
|
+
/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/
|
|
289
320
|
|
|
290
|
-
var entityStart =
|
|
291
|
-
|
|
321
|
+
var entityStart =
|
|
322
|
+
/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/
|
|
323
|
+
var entityBody =
|
|
324
|
+
/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/
|
|
292
325
|
|
|
293
|
-
function isWhitespace
|
|
326
|
+
function isWhitespace(c) {
|
|
294
327
|
return c === ' ' || c === '\n' || c === '\r' || c === '\t'
|
|
295
328
|
}
|
|
296
329
|
|
|
297
|
-
function isQuote
|
|
298
|
-
return c === '"' || c === '
|
|
330
|
+
function isQuote(c) {
|
|
331
|
+
return c === '"' || c === "'"
|
|
299
332
|
}
|
|
300
333
|
|
|
301
|
-
function isAttribEnd
|
|
334
|
+
function isAttribEnd(c) {
|
|
302
335
|
return c === '>' || isWhitespace(c)
|
|
303
336
|
}
|
|
304
337
|
|
|
305
|
-
function isMatch
|
|
338
|
+
function isMatch(regex, c) {
|
|
306
339
|
return regex.test(c)
|
|
307
340
|
}
|
|
308
341
|
|
|
309
|
-
function notMatch
|
|
342
|
+
function notMatch(regex, c) {
|
|
310
343
|
return !isMatch(regex, c)
|
|
311
344
|
}
|
|
312
345
|
|
|
@@ -347,271 +380,271 @@
|
|
|
347
380
|
CLOSE_TAG: S++, // </a
|
|
348
381
|
CLOSE_TAG_SAW_WHITE: S++, // </a >
|
|
349
382
|
SCRIPT: S++, // <script> ...
|
|
350
|
-
SCRIPT_ENDING: S
|
|
383
|
+
SCRIPT_ENDING: S++, // <script> ... <
|
|
351
384
|
}
|
|
352
385
|
|
|
353
386
|
sax.XML_ENTITIES = {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
387
|
+
amp: '&',
|
|
388
|
+
gt: '>',
|
|
389
|
+
lt: '<',
|
|
390
|
+
quot: '"',
|
|
391
|
+
apos: "'",
|
|
359
392
|
}
|
|
360
393
|
|
|
361
394
|
sax.ENTITIES = {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
395
|
+
amp: '&',
|
|
396
|
+
gt: '>',
|
|
397
|
+
lt: '<',
|
|
398
|
+
quot: '"',
|
|
399
|
+
apos: "'",
|
|
400
|
+
AElig: 198,
|
|
401
|
+
Aacute: 193,
|
|
402
|
+
Acirc: 194,
|
|
403
|
+
Agrave: 192,
|
|
404
|
+
Aring: 197,
|
|
405
|
+
Atilde: 195,
|
|
406
|
+
Auml: 196,
|
|
407
|
+
Ccedil: 199,
|
|
408
|
+
ETH: 208,
|
|
409
|
+
Eacute: 201,
|
|
410
|
+
Ecirc: 202,
|
|
411
|
+
Egrave: 200,
|
|
412
|
+
Euml: 203,
|
|
413
|
+
Iacute: 205,
|
|
414
|
+
Icirc: 206,
|
|
415
|
+
Igrave: 204,
|
|
416
|
+
Iuml: 207,
|
|
417
|
+
Ntilde: 209,
|
|
418
|
+
Oacute: 211,
|
|
419
|
+
Ocirc: 212,
|
|
420
|
+
Ograve: 210,
|
|
421
|
+
Oslash: 216,
|
|
422
|
+
Otilde: 213,
|
|
423
|
+
Ouml: 214,
|
|
424
|
+
THORN: 222,
|
|
425
|
+
Uacute: 218,
|
|
426
|
+
Ucirc: 219,
|
|
427
|
+
Ugrave: 217,
|
|
428
|
+
Uuml: 220,
|
|
429
|
+
Yacute: 221,
|
|
430
|
+
aacute: 225,
|
|
431
|
+
acirc: 226,
|
|
432
|
+
aelig: 230,
|
|
433
|
+
agrave: 224,
|
|
434
|
+
aring: 229,
|
|
435
|
+
atilde: 227,
|
|
436
|
+
auml: 228,
|
|
437
|
+
ccedil: 231,
|
|
438
|
+
eacute: 233,
|
|
439
|
+
ecirc: 234,
|
|
440
|
+
egrave: 232,
|
|
441
|
+
eth: 240,
|
|
442
|
+
euml: 235,
|
|
443
|
+
iacute: 237,
|
|
444
|
+
icirc: 238,
|
|
445
|
+
igrave: 236,
|
|
446
|
+
iuml: 239,
|
|
447
|
+
ntilde: 241,
|
|
448
|
+
oacute: 243,
|
|
449
|
+
ocirc: 244,
|
|
450
|
+
ograve: 242,
|
|
451
|
+
oslash: 248,
|
|
452
|
+
otilde: 245,
|
|
453
|
+
ouml: 246,
|
|
454
|
+
szlig: 223,
|
|
455
|
+
thorn: 254,
|
|
456
|
+
uacute: 250,
|
|
457
|
+
ucirc: 251,
|
|
458
|
+
ugrave: 249,
|
|
459
|
+
uuml: 252,
|
|
460
|
+
yacute: 253,
|
|
461
|
+
yuml: 255,
|
|
462
|
+
copy: 169,
|
|
463
|
+
reg: 174,
|
|
464
|
+
nbsp: 160,
|
|
465
|
+
iexcl: 161,
|
|
466
|
+
cent: 162,
|
|
467
|
+
pound: 163,
|
|
468
|
+
curren: 164,
|
|
469
|
+
yen: 165,
|
|
470
|
+
brvbar: 166,
|
|
471
|
+
sect: 167,
|
|
472
|
+
uml: 168,
|
|
473
|
+
ordf: 170,
|
|
474
|
+
laquo: 171,
|
|
475
|
+
not: 172,
|
|
476
|
+
shy: 173,
|
|
477
|
+
macr: 175,
|
|
478
|
+
deg: 176,
|
|
479
|
+
plusmn: 177,
|
|
480
|
+
sup1: 185,
|
|
481
|
+
sup2: 178,
|
|
482
|
+
sup3: 179,
|
|
483
|
+
acute: 180,
|
|
484
|
+
micro: 181,
|
|
485
|
+
para: 182,
|
|
486
|
+
middot: 183,
|
|
487
|
+
cedil: 184,
|
|
488
|
+
ordm: 186,
|
|
489
|
+
raquo: 187,
|
|
490
|
+
frac14: 188,
|
|
491
|
+
frac12: 189,
|
|
492
|
+
frac34: 190,
|
|
493
|
+
iquest: 191,
|
|
494
|
+
times: 215,
|
|
495
|
+
divide: 247,
|
|
496
|
+
OElig: 338,
|
|
497
|
+
oelig: 339,
|
|
498
|
+
Scaron: 352,
|
|
499
|
+
scaron: 353,
|
|
500
|
+
Yuml: 376,
|
|
501
|
+
fnof: 402,
|
|
502
|
+
circ: 710,
|
|
503
|
+
tilde: 732,
|
|
504
|
+
Alpha: 913,
|
|
505
|
+
Beta: 914,
|
|
506
|
+
Gamma: 915,
|
|
507
|
+
Delta: 916,
|
|
508
|
+
Epsilon: 917,
|
|
509
|
+
Zeta: 918,
|
|
510
|
+
Eta: 919,
|
|
511
|
+
Theta: 920,
|
|
512
|
+
Iota: 921,
|
|
513
|
+
Kappa: 922,
|
|
514
|
+
Lambda: 923,
|
|
515
|
+
Mu: 924,
|
|
516
|
+
Nu: 925,
|
|
517
|
+
Xi: 926,
|
|
518
|
+
Omicron: 927,
|
|
519
|
+
Pi: 928,
|
|
520
|
+
Rho: 929,
|
|
521
|
+
Sigma: 931,
|
|
522
|
+
Tau: 932,
|
|
523
|
+
Upsilon: 933,
|
|
524
|
+
Phi: 934,
|
|
525
|
+
Chi: 935,
|
|
526
|
+
Psi: 936,
|
|
527
|
+
Omega: 937,
|
|
528
|
+
alpha: 945,
|
|
529
|
+
beta: 946,
|
|
530
|
+
gamma: 947,
|
|
531
|
+
delta: 948,
|
|
532
|
+
epsilon: 949,
|
|
533
|
+
zeta: 950,
|
|
534
|
+
eta: 951,
|
|
535
|
+
theta: 952,
|
|
536
|
+
iota: 953,
|
|
537
|
+
kappa: 954,
|
|
538
|
+
lambda: 955,
|
|
539
|
+
mu: 956,
|
|
540
|
+
nu: 957,
|
|
541
|
+
xi: 958,
|
|
542
|
+
omicron: 959,
|
|
543
|
+
pi: 960,
|
|
544
|
+
rho: 961,
|
|
545
|
+
sigmaf: 962,
|
|
546
|
+
sigma: 963,
|
|
547
|
+
tau: 964,
|
|
548
|
+
upsilon: 965,
|
|
549
|
+
phi: 966,
|
|
550
|
+
chi: 967,
|
|
551
|
+
psi: 968,
|
|
552
|
+
omega: 969,
|
|
553
|
+
thetasym: 977,
|
|
554
|
+
upsih: 978,
|
|
555
|
+
piv: 982,
|
|
556
|
+
ensp: 8194,
|
|
557
|
+
emsp: 8195,
|
|
558
|
+
thinsp: 8201,
|
|
559
|
+
zwnj: 8204,
|
|
560
|
+
zwj: 8205,
|
|
561
|
+
lrm: 8206,
|
|
562
|
+
rlm: 8207,
|
|
563
|
+
ndash: 8211,
|
|
564
|
+
mdash: 8212,
|
|
565
|
+
lsquo: 8216,
|
|
566
|
+
rsquo: 8217,
|
|
567
|
+
sbquo: 8218,
|
|
568
|
+
ldquo: 8220,
|
|
569
|
+
rdquo: 8221,
|
|
570
|
+
bdquo: 8222,
|
|
571
|
+
dagger: 8224,
|
|
572
|
+
Dagger: 8225,
|
|
573
|
+
bull: 8226,
|
|
574
|
+
hellip: 8230,
|
|
575
|
+
permil: 8240,
|
|
576
|
+
prime: 8242,
|
|
577
|
+
Prime: 8243,
|
|
578
|
+
lsaquo: 8249,
|
|
579
|
+
rsaquo: 8250,
|
|
580
|
+
oline: 8254,
|
|
581
|
+
frasl: 8260,
|
|
582
|
+
euro: 8364,
|
|
583
|
+
image: 8465,
|
|
584
|
+
weierp: 8472,
|
|
585
|
+
real: 8476,
|
|
586
|
+
trade: 8482,
|
|
587
|
+
alefsym: 8501,
|
|
588
|
+
larr: 8592,
|
|
589
|
+
uarr: 8593,
|
|
590
|
+
rarr: 8594,
|
|
591
|
+
darr: 8595,
|
|
592
|
+
harr: 8596,
|
|
593
|
+
crarr: 8629,
|
|
594
|
+
lArr: 8656,
|
|
595
|
+
uArr: 8657,
|
|
596
|
+
rArr: 8658,
|
|
597
|
+
dArr: 8659,
|
|
598
|
+
hArr: 8660,
|
|
599
|
+
forall: 8704,
|
|
600
|
+
part: 8706,
|
|
601
|
+
exist: 8707,
|
|
602
|
+
empty: 8709,
|
|
603
|
+
nabla: 8711,
|
|
604
|
+
isin: 8712,
|
|
605
|
+
notin: 8713,
|
|
606
|
+
ni: 8715,
|
|
607
|
+
prod: 8719,
|
|
608
|
+
sum: 8721,
|
|
609
|
+
minus: 8722,
|
|
610
|
+
lowast: 8727,
|
|
611
|
+
radic: 8730,
|
|
612
|
+
prop: 8733,
|
|
613
|
+
infin: 8734,
|
|
614
|
+
ang: 8736,
|
|
615
|
+
and: 8743,
|
|
616
|
+
or: 8744,
|
|
617
|
+
cap: 8745,
|
|
618
|
+
cup: 8746,
|
|
619
|
+
int: 8747,
|
|
620
|
+
there4: 8756,
|
|
621
|
+
sim: 8764,
|
|
622
|
+
cong: 8773,
|
|
623
|
+
asymp: 8776,
|
|
624
|
+
ne: 8800,
|
|
625
|
+
equiv: 8801,
|
|
626
|
+
le: 8804,
|
|
627
|
+
ge: 8805,
|
|
628
|
+
sub: 8834,
|
|
629
|
+
sup: 8835,
|
|
630
|
+
nsub: 8836,
|
|
631
|
+
sube: 8838,
|
|
632
|
+
supe: 8839,
|
|
633
|
+
oplus: 8853,
|
|
634
|
+
otimes: 8855,
|
|
635
|
+
perp: 8869,
|
|
636
|
+
sdot: 8901,
|
|
637
|
+
lceil: 8968,
|
|
638
|
+
rceil: 8969,
|
|
639
|
+
lfloor: 8970,
|
|
640
|
+
rfloor: 8971,
|
|
641
|
+
lang: 9001,
|
|
642
|
+
rang: 9002,
|
|
643
|
+
loz: 9674,
|
|
644
|
+
spades: 9824,
|
|
645
|
+
clubs: 9827,
|
|
646
|
+
hearts: 9829,
|
|
647
|
+
diams: 9830,
|
|
615
648
|
}
|
|
616
649
|
|
|
617
650
|
Object.keys(sax.ENTITIES).forEach(function (key) {
|
|
@@ -627,33 +660,37 @@
|
|
|
627
660
|
// shorthand
|
|
628
661
|
S = sax.STATE
|
|
629
662
|
|
|
630
|
-
function emit
|
|
663
|
+
function emit(parser, event, data) {
|
|
631
664
|
parser[event] && parser[event](data)
|
|
632
665
|
}
|
|
633
666
|
|
|
634
|
-
function emitNode
|
|
667
|
+
function emitNode(parser, nodeType, data) {
|
|
635
668
|
if (parser.textNode) closeText(parser)
|
|
636
669
|
emit(parser, nodeType, data)
|
|
637
670
|
}
|
|
638
671
|
|
|
639
|
-
function closeText
|
|
672
|
+
function closeText(parser) {
|
|
640
673
|
parser.textNode = textopts(parser.opt, parser.textNode)
|
|
641
674
|
if (parser.textNode) emit(parser, 'ontext', parser.textNode)
|
|
642
675
|
parser.textNode = ''
|
|
643
676
|
}
|
|
644
677
|
|
|
645
|
-
function textopts
|
|
678
|
+
function textopts(opt, text) {
|
|
646
679
|
if (opt.trim) text = text.trim()
|
|
647
680
|
if (opt.normalize) text = text.replace(/\s+/g, ' ')
|
|
648
681
|
return text
|
|
649
682
|
}
|
|
650
683
|
|
|
651
|
-
function error
|
|
684
|
+
function error(parser, er) {
|
|
652
685
|
closeText(parser)
|
|
653
686
|
if (parser.trackPosition) {
|
|
654
|
-
er +=
|
|
655
|
-
'\
|
|
656
|
-
|
|
687
|
+
er +=
|
|
688
|
+
'\nLine: ' +
|
|
689
|
+
parser.line +
|
|
690
|
+
'\nColumn: ' +
|
|
691
|
+
parser.column +
|
|
692
|
+
'\nChar: ' +
|
|
693
|
+
parser.c
|
|
657
694
|
}
|
|
658
695
|
er = new Error(er)
|
|
659
696
|
parser.error = er
|
|
@@ -661,11 +698,14 @@
|
|
|
661
698
|
return parser
|
|
662
699
|
}
|
|
663
700
|
|
|
664
|
-
function end
|
|
665
|
-
if (parser.sawRoot && !parser.closedRoot)
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
701
|
+
function end(parser) {
|
|
702
|
+
if (parser.sawRoot && !parser.closedRoot)
|
|
703
|
+
strictFail(parser, 'Unclosed root tag')
|
|
704
|
+
if (
|
|
705
|
+
parser.state !== S.BEGIN &&
|
|
706
|
+
parser.state !== S.BEGIN_WHITESPACE &&
|
|
707
|
+
parser.state !== S.TEXT
|
|
708
|
+
) {
|
|
669
709
|
error(parser, 'Unexpected end')
|
|
670
710
|
}
|
|
671
711
|
closeText(parser)
|
|
@@ -676,7 +716,7 @@
|
|
|
676
716
|
return parser
|
|
677
717
|
}
|
|
678
718
|
|
|
679
|
-
function strictFail
|
|
719
|
+
function strictFail(parser, message) {
|
|
680
720
|
if (typeof parser !== 'object' || !(parser instanceof SAXParser)) {
|
|
681
721
|
throw new Error('bad call to strictFail')
|
|
682
722
|
}
|
|
@@ -685,10 +725,10 @@
|
|
|
685
725
|
}
|
|
686
726
|
}
|
|
687
727
|
|
|
688
|
-
function newTag
|
|
728
|
+
function newTag(parser) {
|
|
689
729
|
if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]()
|
|
690
730
|
var parent = parser.tags[parser.tags.length - 1] || parser
|
|
691
|
-
var tag = parser.tag = { name: parser.tagName, attributes: {} }
|
|
731
|
+
var tag = (parser.tag = { name: parser.tagName, attributes: {} })
|
|
692
732
|
|
|
693
733
|
// will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar"
|
|
694
734
|
if (parser.opt.xmlns) {
|
|
@@ -698,9 +738,9 @@
|
|
|
698
738
|
emitNode(parser, 'onopentagstart', tag)
|
|
699
739
|
}
|
|
700
740
|
|
|
701
|
-
function qname
|
|
741
|
+
function qname(name, attribute) {
|
|
702
742
|
var i = name.indexOf(':')
|
|
703
|
-
var qualName = i < 0 ? [
|
|
743
|
+
var qualName = i < 0 ? ['', name] : name.split(':')
|
|
704
744
|
var prefix = qualName[0]
|
|
705
745
|
var local = qualName[1]
|
|
706
746
|
|
|
@@ -713,13 +753,15 @@
|
|
|
713
753
|
return { prefix: prefix, local: local }
|
|
714
754
|
}
|
|
715
755
|
|
|
716
|
-
function attrib
|
|
756
|
+
function attrib(parser) {
|
|
717
757
|
if (!parser.strict) {
|
|
718
758
|
parser.attribName = parser.attribName[parser.looseCase]()
|
|
719
759
|
}
|
|
720
760
|
|
|
721
|
-
if (
|
|
722
|
-
parser.
|
|
761
|
+
if (
|
|
762
|
+
parser.attribList.indexOf(parser.attribName) !== -1 ||
|
|
763
|
+
parser.tag.attributes.hasOwnProperty(parser.attribName)
|
|
764
|
+
) {
|
|
723
765
|
parser.attribName = parser.attribValue = ''
|
|
724
766
|
return
|
|
725
767
|
}
|
|
@@ -732,13 +774,26 @@
|
|
|
732
774
|
if (prefix === 'xmlns') {
|
|
733
775
|
// namespace binding attribute. push the binding into scope
|
|
734
776
|
if (local === 'xml' && parser.attribValue !== XML_NAMESPACE) {
|
|
735
|
-
strictFail(
|
|
736
|
-
|
|
737
|
-
'
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
777
|
+
strictFail(
|
|
778
|
+
parser,
|
|
779
|
+
'xml: prefix must be bound to ' +
|
|
780
|
+
XML_NAMESPACE +
|
|
781
|
+
'\n' +
|
|
782
|
+
'Actual: ' +
|
|
783
|
+
parser.attribValue,
|
|
784
|
+
)
|
|
785
|
+
} else if (
|
|
786
|
+
local === 'xmlns' &&
|
|
787
|
+
parser.attribValue !== XMLNS_NAMESPACE
|
|
788
|
+
) {
|
|
789
|
+
strictFail(
|
|
790
|
+
parser,
|
|
791
|
+
'xmlns: prefix must be bound to ' +
|
|
792
|
+
XMLNS_NAMESPACE +
|
|
793
|
+
'\n' +
|
|
794
|
+
'Actual: ' +
|
|
795
|
+
parser.attribValue,
|
|
796
|
+
)
|
|
742
797
|
} else {
|
|
743
798
|
var tag = parser.tag
|
|
744
799
|
var parent = parser.tags[parser.tags.length - 1] || parser
|
|
@@ -758,14 +813,14 @@
|
|
|
758
813
|
parser.tag.attributes[parser.attribName] = parser.attribValue
|
|
759
814
|
emitNode(parser, 'onattribute', {
|
|
760
815
|
name: parser.attribName,
|
|
761
|
-
value: parser.attribValue
|
|
816
|
+
value: parser.attribValue,
|
|
762
817
|
})
|
|
763
818
|
}
|
|
764
819
|
|
|
765
820
|
parser.attribName = parser.attribValue = ''
|
|
766
821
|
}
|
|
767
822
|
|
|
768
|
-
function openTag
|
|
823
|
+
function openTag(parser, selfClosing) {
|
|
769
824
|
if (parser.opt.xmlns) {
|
|
770
825
|
// emit namespace binding events
|
|
771
826
|
var tag = parser.tag
|
|
@@ -777,8 +832,10 @@
|
|
|
777
832
|
tag.uri = tag.ns[qn.prefix] || ''
|
|
778
833
|
|
|
779
834
|
if (tag.prefix && !tag.uri) {
|
|
780
|
-
strictFail(
|
|
781
|
-
|
|
835
|
+
strictFail(
|
|
836
|
+
parser,
|
|
837
|
+
'Unbound namespace prefix: ' + JSON.stringify(parser.tagName),
|
|
838
|
+
)
|
|
782
839
|
tag.uri = qn.prefix
|
|
783
840
|
}
|
|
784
841
|
|
|
@@ -787,7 +844,7 @@
|
|
|
787
844
|
Object.keys(tag.ns).forEach(function (p) {
|
|
788
845
|
emitNode(parser, 'onopennamespace', {
|
|
789
846
|
prefix: p,
|
|
790
|
-
uri: tag.ns[p]
|
|
847
|
+
uri: tag.ns[p],
|
|
791
848
|
})
|
|
792
849
|
})
|
|
793
850
|
}
|
|
@@ -802,20 +859,22 @@
|
|
|
802
859
|
var qualName = qname(name, true)
|
|
803
860
|
var prefix = qualName.prefix
|
|
804
861
|
var local = qualName.local
|
|
805
|
-
var uri = prefix === '' ? '' :
|
|
862
|
+
var uri = prefix === '' ? '' : tag.ns[prefix] || ''
|
|
806
863
|
var a = {
|
|
807
864
|
name: name,
|
|
808
865
|
value: value,
|
|
809
866
|
prefix: prefix,
|
|
810
867
|
local: local,
|
|
811
|
-
uri: uri
|
|
868
|
+
uri: uri,
|
|
812
869
|
}
|
|
813
870
|
|
|
814
871
|
// if there's any attributes with an undefined namespace,
|
|
815
872
|
// then fail on them now.
|
|
816
873
|
if (prefix && prefix !== 'xmlns' && !uri) {
|
|
817
|
-
strictFail(
|
|
818
|
-
|
|
874
|
+
strictFail(
|
|
875
|
+
parser,
|
|
876
|
+
'Unbound namespace prefix: ' + JSON.stringify(prefix),
|
|
877
|
+
)
|
|
819
878
|
a.uri = prefix
|
|
820
879
|
}
|
|
821
880
|
parser.tag.attributes[name] = a
|
|
@@ -844,7 +903,7 @@
|
|
|
844
903
|
parser.attribList.length = 0
|
|
845
904
|
}
|
|
846
905
|
|
|
847
|
-
function closeTag
|
|
906
|
+
function closeTag(parser) {
|
|
848
907
|
if (!parser.tagName) {
|
|
849
908
|
strictFail(parser, 'Weird empty close tag.')
|
|
850
909
|
parser.textNode += '</>'
|
|
@@ -891,7 +950,7 @@
|
|
|
891
950
|
parser.tagName = tagName
|
|
892
951
|
var s = parser.tags.length
|
|
893
952
|
while (s-- > t) {
|
|
894
|
-
var tag = parser.tag = parser.tags.pop()
|
|
953
|
+
var tag = (parser.tag = parser.tags.pop())
|
|
895
954
|
parser.tagName = parser.tag.name
|
|
896
955
|
emitNode(parser, 'onclosetag', parser.tagName)
|
|
897
956
|
|
|
@@ -915,7 +974,7 @@
|
|
|
915
974
|
parser.state = S.TEXT
|
|
916
975
|
}
|
|
917
976
|
|
|
918
|
-
function parseEntity
|
|
977
|
+
function parseEntity(parser) {
|
|
919
978
|
var entity = parser.entity
|
|
920
979
|
var entityLC = entity.toLowerCase()
|
|
921
980
|
var num
|
|
@@ -948,7 +1007,7 @@
|
|
|
948
1007
|
return String.fromCodePoint(num)
|
|
949
1008
|
}
|
|
950
1009
|
|
|
951
|
-
function beginWhiteSpace
|
|
1010
|
+
function beginWhiteSpace(parser, c) {
|
|
952
1011
|
if (c === '<') {
|
|
953
1012
|
parser.state = S.OPEN_WAKA
|
|
954
1013
|
parser.startTagPosition = parser.position
|
|
@@ -961,7 +1020,7 @@
|
|
|
961
1020
|
}
|
|
962
1021
|
}
|
|
963
1022
|
|
|
964
|
-
function charAt
|
|
1023
|
+
function charAt(chunk, i) {
|
|
965
1024
|
var result = ''
|
|
966
1025
|
if (i < chunk.length) {
|
|
967
1026
|
result = chunk.charAt(i)
|
|
@@ -969,14 +1028,16 @@
|
|
|
969
1028
|
return result
|
|
970
1029
|
}
|
|
971
1030
|
|
|
972
|
-
function write
|
|
1031
|
+
function write(chunk) {
|
|
973
1032
|
var parser = this
|
|
974
1033
|
if (this.error) {
|
|
975
1034
|
throw this.error
|
|
976
1035
|
}
|
|
977
1036
|
if (parser.closed) {
|
|
978
|
-
return error(
|
|
979
|
-
|
|
1037
|
+
return error(
|
|
1038
|
+
parser,
|
|
1039
|
+
'Cannot write after close. Assign an onready handler.',
|
|
1040
|
+
)
|
|
980
1041
|
}
|
|
981
1042
|
if (chunk === null) {
|
|
982
1043
|
return end(parser)
|
|
@@ -1034,11 +1095,17 @@
|
|
|
1034
1095
|
}
|
|
1035
1096
|
parser.textNode += chunk.substring(starti, i - 1)
|
|
1036
1097
|
}
|
|
1037
|
-
if (
|
|
1098
|
+
if (
|
|
1099
|
+
c === '<' &&
|
|
1100
|
+
!(parser.sawRoot && parser.closedRoot && !parser.strict)
|
|
1101
|
+
) {
|
|
1038
1102
|
parser.state = S.OPEN_WAKA
|
|
1039
1103
|
parser.startTagPosition = parser.position
|
|
1040
1104
|
} else {
|
|
1041
|
-
if (
|
|
1105
|
+
if (
|
|
1106
|
+
!isWhitespace(c) &&
|
|
1107
|
+
(!parser.sawRoot || parser.closedRoot)
|
|
1108
|
+
) {
|
|
1042
1109
|
strictFail(parser, 'Text data outside of root node.')
|
|
1043
1110
|
}
|
|
1044
1111
|
if (c === '&') {
|
|
@@ -1100,10 +1167,14 @@
|
|
|
1100
1167
|
parser.state = S.COMMENT
|
|
1101
1168
|
parser.comment = ''
|
|
1102
1169
|
parser.sgmlDecl = ''
|
|
1103
|
-
continue
|
|
1170
|
+
continue
|
|
1104
1171
|
}
|
|
1105
1172
|
|
|
1106
|
-
if (
|
|
1173
|
+
if (
|
|
1174
|
+
parser.doctype &&
|
|
1175
|
+
parser.doctype !== true &&
|
|
1176
|
+
parser.sgmlDecl
|
|
1177
|
+
) {
|
|
1107
1178
|
parser.state = S.DOCTYPE_DTD
|
|
1108
1179
|
parser.doctype += '<!' + parser.sgmlDecl + c
|
|
1109
1180
|
parser.sgmlDecl = ''
|
|
@@ -1115,8 +1186,10 @@
|
|
|
1115
1186
|
} else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
|
|
1116
1187
|
parser.state = S.DOCTYPE
|
|
1117
1188
|
if (parser.doctype || parser.sawRoot) {
|
|
1118
|
-
strictFail(
|
|
1119
|
-
|
|
1189
|
+
strictFail(
|
|
1190
|
+
parser,
|
|
1191
|
+
'Inappropriately located doctype declaration',
|
|
1192
|
+
)
|
|
1120
1193
|
}
|
|
1121
1194
|
parser.doctype = ''
|
|
1122
1195
|
parser.sgmlDecl = ''
|
|
@@ -1225,10 +1298,22 @@
|
|
|
1225
1298
|
continue
|
|
1226
1299
|
|
|
1227
1300
|
case S.CDATA:
|
|
1301
|
+
var starti = i - 1
|
|
1302
|
+
while (c && c !== ']') {
|
|
1303
|
+
c = charAt(chunk, i++)
|
|
1304
|
+
if (c && parser.trackPosition) {
|
|
1305
|
+
parser.position++
|
|
1306
|
+
if (c === '\n') {
|
|
1307
|
+
parser.line++
|
|
1308
|
+
parser.column = 0
|
|
1309
|
+
} else {
|
|
1310
|
+
parser.column++
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
parser.cdata += chunk.substring(starti, i - 1)
|
|
1228
1315
|
if (c === ']') {
|
|
1229
1316
|
parser.state = S.CDATA_ENDING
|
|
1230
|
-
} else {
|
|
1231
|
-
parser.cdata += c
|
|
1232
1317
|
}
|
|
1233
1318
|
continue
|
|
1234
1319
|
|
|
@@ -1281,7 +1366,7 @@
|
|
|
1281
1366
|
if (c === '>') {
|
|
1282
1367
|
emitNode(parser, 'onprocessinginstruction', {
|
|
1283
1368
|
name: parser.procInstName,
|
|
1284
|
-
body: parser.procInstBody
|
|
1369
|
+
body: parser.procInstBody,
|
|
1285
1370
|
})
|
|
1286
1371
|
parser.procInstName = parser.procInstBody = ''
|
|
1287
1372
|
parser.state = S.TEXT
|
|
@@ -1314,7 +1399,10 @@
|
|
|
1314
1399
|
openTag(parser, true)
|
|
1315
1400
|
closeTag(parser)
|
|
1316
1401
|
} else {
|
|
1317
|
-
strictFail(
|
|
1402
|
+
strictFail(
|
|
1403
|
+
parser,
|
|
1404
|
+
'Forward-slash in opening tag not followed by >',
|
|
1405
|
+
)
|
|
1318
1406
|
parser.state = S.ATTRIB
|
|
1319
1407
|
}
|
|
1320
1408
|
continue
|
|
@@ -1364,7 +1452,7 @@
|
|
|
1364
1452
|
parser.attribValue = ''
|
|
1365
1453
|
emitNode(parser, 'onattribute', {
|
|
1366
1454
|
name: parser.attribName,
|
|
1367
|
-
value: ''
|
|
1455
|
+
value: '',
|
|
1368
1456
|
})
|
|
1369
1457
|
parser.attribName = ''
|
|
1370
1458
|
if (c === '>') {
|
|
@@ -1507,7 +1595,10 @@
|
|
|
1507
1595
|
|
|
1508
1596
|
if (c === ';') {
|
|
1509
1597
|
var parsedEntity = parseEntity(parser)
|
|
1510
|
-
if (
|
|
1598
|
+
if (
|
|
1599
|
+
parser.opt.unparsedEntities &&
|
|
1600
|
+
!Object.values(sax.XML_ENTITIES).includes(parsedEntity)
|
|
1601
|
+
) {
|
|
1511
1602
|
parser.entity = ''
|
|
1512
1603
|
parser.state = returnState
|
|
1513
1604
|
parser.write(parsedEntity)
|
|
@@ -1516,7 +1607,9 @@
|
|
|
1516
1607
|
parser.entity = ''
|
|
1517
1608
|
parser.state = returnState
|
|
1518
1609
|
}
|
|
1519
|
-
} else if (
|
|
1610
|
+
} else if (
|
|
1611
|
+
isMatch(parser.entity.length ? entityBody : entityStart, c)
|
|
1612
|
+
) {
|
|
1520
1613
|
parser.entity += c
|
|
1521
1614
|
} else {
|
|
1522
1615
|
strictFail(parser, 'Invalid character in entity name')
|
|
@@ -1542,7 +1635,7 @@
|
|
|
1542
1635
|
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
|
|
1543
1636
|
/* istanbul ignore next */
|
|
1544
1637
|
if (!String.fromCodePoint) {
|
|
1545
|
-
(function () {
|
|
1638
|
+
;(function () {
|
|
1546
1639
|
var stringFromCharCode = String.fromCharCode
|
|
1547
1640
|
var floor = Math.floor
|
|
1548
1641
|
var fromCodePoint = function () {
|
|
@@ -1561,18 +1654,20 @@
|
|
|
1561
1654
|
if (
|
|
1562
1655
|
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
|
1563
1656
|
codePoint < 0 || // not a valid Unicode code point
|
|
1564
|
-
codePoint >
|
|
1657
|
+
codePoint > 0x10ffff || // not a valid Unicode code point
|
|
1565
1658
|
floor(codePoint) !== codePoint // not an integer
|
|
1566
1659
|
) {
|
|
1567
1660
|
throw RangeError('Invalid code point: ' + codePoint)
|
|
1568
1661
|
}
|
|
1569
|
-
if (codePoint <=
|
|
1662
|
+
if (codePoint <= 0xffff) {
|
|
1663
|
+
// BMP code point
|
|
1570
1664
|
codeUnits.push(codePoint)
|
|
1571
|
-
} else {
|
|
1665
|
+
} else {
|
|
1666
|
+
// Astral code point; split in surrogate halves
|
|
1572
1667
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
1573
1668
|
codePoint -= 0x10000
|
|
1574
|
-
highSurrogate = (codePoint >> 10) +
|
|
1575
|
-
lowSurrogate = (codePoint % 0x400) +
|
|
1669
|
+
highSurrogate = (codePoint >> 10) + 0xd800
|
|
1670
|
+
lowSurrogate = (codePoint % 0x400) + 0xdc00
|
|
1576
1671
|
codeUnits.push(highSurrogate, lowSurrogate)
|
|
1577
1672
|
}
|
|
1578
1673
|
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
|
|
@@ -1587,11 +1682,11 @@
|
|
|
1587
1682
|
Object.defineProperty(String, 'fromCodePoint', {
|
|
1588
1683
|
value: fromCodePoint,
|
|
1589
1684
|
configurable: true,
|
|
1590
|
-
writable: true
|
|
1685
|
+
writable: true,
|
|
1591
1686
|
})
|
|
1592
1687
|
} else {
|
|
1593
1688
|
String.fromCodePoint = fromCodePoint
|
|
1594
1689
|
}
|
|
1595
|
-
}()
|
|
1690
|
+
})()
|
|
1596
1691
|
}
|
|
1597
|
-
})(typeof exports === 'undefined' ? this.sax = {} : exports)
|
|
1692
|
+
})(typeof exports === 'undefined' ? (this.sax = {}) : exports)
|