sax 1.3.0 → 1.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The ISC License
2
2
 
3
- Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
3
+ Copyright (c) 2010-2024 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 (c) 2010-2022 Mathias Bynens <https://mathiasbynens.be/>
22
+ Copyright (c) 2010-2024 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) {
@@ -1090,15 +1096,22 @@
1090
1096
  continue
1091
1097
 
1092
1098
  case S.SGML_DECL:
1093
- if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
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 && parser.sgmlDecl) {
1107
+ parser.state = S.DOCTYPE_DTD
1108
+ parser.doctype += '<!' + parser.sgmlDecl + c
1109
+ parser.sgmlDecl = ''
1110
+ } else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
1094
1111
  emitNode(parser, 'onopencdata')
1095
1112
  parser.state = S.CDATA
1096
1113
  parser.sgmlDecl = ''
1097
1114
  parser.cdata = ''
1098
- } else if (parser.sgmlDecl + c === '--') {
1099
- parser.state = S.COMMENT
1100
- parser.comment = ''
1101
- parser.sgmlDecl = ''
1102
1115
  } else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
1103
1116
  parser.state = S.DOCTYPE
1104
1117
  if (parser.doctype || parser.sawRoot) {
@@ -1152,12 +1165,18 @@
1152
1165
  continue
1153
1166
 
1154
1167
  case S.DOCTYPE_DTD:
1155
- parser.doctype += c
1156
1168
  if (c === ']') {
1169
+ parser.doctype += c
1157
1170
  parser.state = S.DOCTYPE
1171
+ } else if (c === '<') {
1172
+ parser.state = S.OPEN_WAKA
1173
+ parser.startTagPosition = parser.position
1158
1174
  } else if (isQuote(c)) {
1175
+ parser.doctype += c
1159
1176
  parser.state = S.DOCTYPE_DTD_QUOTED
1160
1177
  parser.q = c
1178
+ } else {
1179
+ parser.doctype += c
1161
1180
  }
1162
1181
  continue
1163
1182
 
@@ -1198,6 +1217,8 @@
1198
1217
  // which is a comment of " blah -- bloo "
1199
1218
  parser.comment += '--' + c
1200
1219
  parser.state = S.COMMENT
1220
+ } else if (parser.doctype && parser.doctype !== true) {
1221
+ parser.state = S.DOCTYPE_DTD
1201
1222
  } else {
1202
1223
  parser.state = S.TEXT
1203
1224
  }
@@ -1365,7 +1386,9 @@
1365
1386
  parser.q = c
1366
1387
  parser.state = S.ATTRIB_VALUE_QUOTED
1367
1388
  } else {
1368
- strictFail(parser, 'Unquoted attribute value')
1389
+ if (!parser.opt.unquotedAttributeValues) {
1390
+ error(parser, 'Unquoted attribute value')
1391
+ }
1369
1392
  parser.state = S.ATTRIB_VALUE_UNQUOTED
1370
1393
  parser.attribValue = c
1371
1394
  }
@@ -1483,13 +1506,13 @@
1483
1506
  }
1484
1507
 
1485
1508
  if (c === ';') {
1486
- if (parser.opt.unparsedEntities) {
1487
- var parsedEntity = parseEntity(parser)
1509
+ var parsedEntity = parseEntity(parser)
1510
+ if (parser.opt.unparsedEntities && !Object.values(sax.XML_ENTITIES).includes(parsedEntity)) {
1488
1511
  parser.entity = ''
1489
1512
  parser.state = returnState
1490
1513
  parser.write(parsedEntity)
1491
1514
  } else {
1492
- parser[buffer] += parseEntity(parser)
1515
+ parser[buffer] += parsedEntity
1493
1516
  parser.entity = ''
1494
1517
  parser.state = returnState
1495
1518
  }
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.3.0",
5
+ "version": "1.4.1",
6
6
  "main": "lib/sax.js",
7
7
  "license": "ISC",
8
8
  "scripts": {