sax 1.4.2 → 1.4.4

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.
Files changed (2) hide show
  1. package/lib/sax.js +24 -12
  2. package/package.json +4 -1
package/lib/sax.js CHANGED
@@ -263,10 +263,9 @@
263
263
  Buffer.isBuffer(data)
264
264
  ) {
265
265
  if (!this._decoder) {
266
- var SD = require('string_decoder').StringDecoder
267
- this._decoder = new SD('utf8')
266
+ this._decoder = new TextDecoder('utf8')
268
267
  }
269
- data = this._decoder.write(data)
268
+ data = this._decoder.decode(data, { stream: true })
270
269
  }
271
270
 
272
271
  this._parser.write(data.toString())
@@ -278,6 +277,14 @@
278
277
  if (chunk && chunk.length) {
279
278
  this.write(chunk)
280
279
  }
280
+ // Flush any remaining decoded data from the TextDecoder
281
+ if (this._decoder) {
282
+ var remaining = this._decoder.decode()
283
+ if (remaining) {
284
+ this._parser.write(remaining)
285
+ this.emit('data', remaining)
286
+ }
287
+ }
281
288
  this._parser.end()
282
289
  return true
283
290
  }
@@ -780,7 +787,7 @@
780
787
  XML_NAMESPACE +
781
788
  '\n' +
782
789
  'Actual: ' +
783
- parser.attribValue,
790
+ parser.attribValue
784
791
  )
785
792
  } else if (
786
793
  local === 'xmlns' &&
@@ -792,7 +799,7 @@
792
799
  XMLNS_NAMESPACE +
793
800
  '\n' +
794
801
  'Actual: ' +
795
- parser.attribValue,
802
+ parser.attribValue
796
803
  )
797
804
  } else {
798
805
  var tag = parser.tag
@@ -834,7 +841,7 @@
834
841
  if (tag.prefix && !tag.uri) {
835
842
  strictFail(
836
843
  parser,
837
- 'Unbound namespace prefix: ' + JSON.stringify(parser.tagName),
844
+ 'Unbound namespace prefix: ' + JSON.stringify(parser.tagName)
838
845
  )
839
846
  tag.uri = qn.prefix
840
847
  }
@@ -873,7 +880,7 @@
873
880
  if (prefix && prefix !== 'xmlns' && !uri) {
874
881
  strictFail(
875
882
  parser,
876
- 'Unbound namespace prefix: ' + JSON.stringify(prefix),
883
+ 'Unbound namespace prefix: ' + JSON.stringify(prefix)
877
884
  )
878
885
  a.uri = prefix
879
886
  }
@@ -999,7 +1006,12 @@
999
1006
  }
1000
1007
  }
1001
1008
  entity = entity.replace(/^0+/, '')
1002
- if (isNaN(num) || numStr.toLowerCase() !== entity) {
1009
+ if (
1010
+ isNaN(num) ||
1011
+ numStr.toLowerCase() !== entity ||
1012
+ num < 0 ||
1013
+ num > 0x10ffff
1014
+ ) {
1003
1015
  strictFail(parser, 'Invalid character entity')
1004
1016
  return '&' + parser.entity + ';'
1005
1017
  }
@@ -1036,7 +1048,7 @@
1036
1048
  if (parser.closed) {
1037
1049
  return error(
1038
1050
  parser,
1039
- 'Cannot write after close. Assign an onready handler.',
1051
+ 'Cannot write after close. Assign an onready handler.'
1040
1052
  )
1041
1053
  }
1042
1054
  if (chunk === null) {
@@ -1188,7 +1200,7 @@
1188
1200
  if (parser.doctype || parser.sawRoot) {
1189
1201
  strictFail(
1190
1202
  parser,
1191
- 'Inappropriately located doctype declaration',
1203
+ 'Inappropriately located doctype declaration'
1192
1204
  )
1193
1205
  }
1194
1206
  parser.doctype = ''
@@ -1401,7 +1413,7 @@
1401
1413
  } else {
1402
1414
  strictFail(
1403
1415
  parser,
1404
- 'Forward-slash in opening tag not followed by >',
1416
+ 'Forward-slash in opening tag not followed by >'
1405
1417
  )
1406
1418
  parser.state = S.ATTRIB
1407
1419
  }
@@ -1549,7 +1561,7 @@
1549
1561
  } else if (isMatch(nameBody, c)) {
1550
1562
  parser.tagName += c
1551
1563
  } else if (parser.script) {
1552
- parser.script += '</' + parser.tagName
1564
+ parser.script += '</' + parser.tagName + c
1553
1565
  parser.tagName = ''
1554
1566
  parser.state = S.SCRIPT
1555
1567
  } else {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "sax",
3
3
  "description": "An evented streaming XML parser in JavaScript",
4
4
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
5
- "version": "1.4.2",
5
+ "version": "1.4.4",
6
6
  "main": "lib/sax.js",
7
7
  "license": "BlueOak-1.0.0",
8
8
  "scripts": {
@@ -24,5 +24,8 @@
24
24
  },
25
25
  "tap": {
26
26
  "allow-incomplete-coverage": true
27
+ },
28
+ "engines": {
29
+ "node": ">=11.0.0"
27
30
  }
28
31
  }