sax 1.2.4 → 1.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The ISC License
2
2
 
3
- Copyright (c) Isaac Z. Schlueter and Contributors
3
+ Copyright (c) 2010-2023 Isaac Z. Schlueter and Contributors
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
@@ -19,7 +19,7 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
19
  `String.fromCodePoint` by Mathias Bynens used according to terms of MIT
20
20
  License, as follows:
21
21
 
22
- Copyright Mathias Bynens <https://mathiasbynens.be/>
22
+ Copyright (c) 2010-2023 Mathias Bynens <https://mathiasbynens.be/>
23
23
 
24
24
  Permission is hereby granted, free of charge, to any person obtaining
25
25
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -106,6 +106,9 @@ Settings supported:
106
106
  * `strictEntities` - Boolean. If true, only parse [predefined XML
107
107
  entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
108
108
  (`&amp;`, `&apos;`, `&gt;`, `&lt;`, and `&quot;`)
109
+ * `unquotedAttributeValues` - Boolean. If true, then unquoted
110
+ attribute values are allowed. Defaults to `false` when `strict`
111
+ is true, `true` otherwise.
109
112
 
110
113
  ## Methods
111
114
 
package/lib/sax.js CHANGED
@@ -71,6 +71,12 @@
71
71
  parser.ns = Object.create(rootNS)
72
72
  }
73
73
 
74
+ // disallow unquoted attribute values if not otherwise configured
75
+ // and strict mode is true
76
+ if (parser.opt.unquotedAttributeValues === undefined) {
77
+ parser.opt.unquotedAttributeValues = !strict;
78
+ }
79
+
74
80
  // mostly just for error reporting
75
81
  parser.trackPosition = parser.opt.position !== false
76
82
  if (parser.trackPosition) {
@@ -164,6 +170,7 @@
164
170
  } catch (ex) {
165
171
  Stream = function () {}
166
172
  }
173
+ if (!Stream) Stream = function () {}
167
174
 
168
175
  var streamWraps = sax.EVENTS.filter(function (ev) {
169
176
  return ev !== 'error' && ev !== 'end'
@@ -1089,15 +1096,23 @@
1089
1096
  continue
1090
1097
 
1091
1098
  case S.SGML_DECL:
1099
+ if (parser.sgmlDecl + c === '--') {
1100
+ parser.state = S.COMMENT
1101
+ parser.comment = ''
1102
+ parser.sgmlDecl = ''
1103
+ continue;
1104
+ }
1105
+
1106
+ if (parser.doctype && parser.doctype !== true) {
1107
+ parser.sgmlDecl += c
1108
+ continue;
1109
+ }
1110
+
1092
1111
  if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
1093
1112
  emitNode(parser, 'onopencdata')
1094
1113
  parser.state = S.CDATA
1095
1114
  parser.sgmlDecl = ''
1096
1115
  parser.cdata = ''
1097
- } else if (parser.sgmlDecl + c === '--') {
1098
- parser.state = S.COMMENT
1099
- parser.comment = ''
1100
- parser.sgmlDecl = ''
1101
1116
  } else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
1102
1117
  parser.state = S.DOCTYPE
1103
1118
  if (parser.doctype || parser.sawRoot) {
@@ -1151,10 +1166,14 @@
1151
1166
  continue
1152
1167
 
1153
1168
  case S.DOCTYPE_DTD:
1154
- parser.doctype += c
1155
1169
  if (c === ']') {
1170
+ parser.doctype += c
1156
1171
  parser.state = S.DOCTYPE
1172
+ } else if (c === '<') {
1173
+ parser.state = S.OPEN_WAKA
1174
+ parser.startTagPosition = parser.position
1157
1175
  } else if (isQuote(c)) {
1176
+ parser.doctype += c
1158
1177
  parser.state = S.DOCTYPE_DTD_QUOTED
1159
1178
  parser.q = c
1160
1179
  }
@@ -1197,6 +1216,8 @@
1197
1216
  // which is a comment of " blah -- bloo "
1198
1217
  parser.comment += '--' + c
1199
1218
  parser.state = S.COMMENT
1219
+ } else if (parser.doctype && parser.doctype !== true) {
1220
+ parser.state = S.DOCTYPE_DTD
1200
1221
  } else {
1201
1222
  parser.state = S.TEXT
1202
1223
  }
@@ -1364,7 +1385,9 @@
1364
1385
  parser.q = c
1365
1386
  parser.state = S.ATTRIB_VALUE_QUOTED
1366
1387
  } else {
1367
- strictFail(parser, 'Unquoted attribute value')
1388
+ if (!parser.opt.unquotedAttributeValues) {
1389
+ error(parser, 'Unquoted attribute value')
1390
+ }
1368
1391
  parser.state = S.ATTRIB_VALUE_UNQUOTED
1369
1392
  parser.attribValue = c
1370
1393
  }
@@ -1482,9 +1505,16 @@
1482
1505
  }
1483
1506
 
1484
1507
  if (c === ';') {
1485
- parser[buffer] += parseEntity(parser)
1486
- parser.entity = ''
1487
- parser.state = returnState
1508
+ var parsedEntity = parseEntity(parser)
1509
+ if (parser.opt.unparsedEntities && !Object.values(sax.XML_ENTITIES).includes(parsedEntity)) {
1510
+ parser.entity = ''
1511
+ parser.state = returnState
1512
+ parser.write(parsedEntity)
1513
+ } else {
1514
+ parser[buffer] += parsedEntity
1515
+ parser.entity = ''
1516
+ parser.state = returnState
1517
+ }
1488
1518
  } else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {
1489
1519
  parser.entity += c
1490
1520
  } else {
@@ -1496,8 +1526,9 @@
1496
1526
 
1497
1527
  continue
1498
1528
 
1499
- default:
1529
+ default: /* istanbul ignore next */ {
1500
1530
  throw new Error(parser, 'Unknown state: ' + parser.state)
1531
+ }
1501
1532
  }
1502
1533
  } // while
1503
1534
 
package/package.json CHANGED
@@ -2,12 +2,11 @@
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.2.4",
5
+ "version": "1.4.0",
6
6
  "main": "lib/sax.js",
7
7
  "license": "ISC",
8
8
  "scripts": {
9
9
  "test": "tap test/*.js --cov -j4",
10
- "posttest": "standard -F test/*.js lib/*.js",
11
10
  "preversion": "npm test",
12
11
  "postversion": "npm publish",
13
12
  "postpublish": "git push origin --all; git push origin --tags"
@@ -19,7 +18,12 @@
19
18
  "README.md"
20
19
  ],
21
20
  "devDependencies": {
22
- "standard": "^8.6.0",
23
- "tap": "^10.5.1"
21
+ "tap": "^15.1.6"
22
+ },
23
+ "tap": {
24
+ "statements": 79,
25
+ "branches": 75,
26
+ "functions": 80,
27
+ "lines": 79
24
28
  }
25
29
  }