You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

sax

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sax - npm Package Compare versions

Comparing version
1.4.1
to
1.4.2
+55
LICENSE.md
# Blue Oak Model License
Version 1.0.0
## Purpose
This license gives everyone as much permission to work with
this software as possible, while protecting contributors
from liability.
## Acceptance
In order to receive this license, you must agree to its
rules. The rules of this license are both obligations
under that agreement and conditions to your license.
You must not do anything with this software that triggers
a rule that you cannot or will not follow.
## Copyright
Each contributor licenses you to do everything with this
software that would otherwise infringe that contributor's
copyright in it.
## Notices
You must ensure that everyone who gets a copy of
any part of this software from you, with or without
changes, also gets the text of this license or a link to
<https://blueoakcouncil.org/license/1.0.0>.
## Excuse
If anyone notifies you in writing that you have not
complied with [Notices](#notices), you can keep your
license by taking all practical steps to comply within 30
days after the notice. If you do not do so, your license
ends immediately.
## Patent
Each contributor licenses you to do everything with this
software that would otherwise infringe any patent claims
they can license or become able to license.
## Reliability
No contributor can revoke this license.
## No Liability
***As far as the law allows, this software comes as is,
without any warranty or condition, and no contributor
will be liable to anyone for any damages related to this
software or this license, under any kind of legal claim.***
+456
-361

@@ -1,3 +0,6 @@

;(function (sax) { // wrapper for non-node envs
sax.parser = function (strict, opt) { return new SAXParser(strict, opt) }
;(function (sax) {
// wrapper for non-node envs
sax.parser = function (strict, opt) {
return new SAXParser(strict, opt)
}
sax.SAXParser = SAXParser

@@ -19,5 +22,14 @@ sax.SAXStream = SAXStream

var buffers = [
'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype',
'procInstName', 'procInstBody', 'entity', 'attribName',
'attribValue', 'cdata', 'script'
'comment',
'sgmlDecl',
'textNode',
'tagName',
'doctype',
'procInstName',
'procInstBody',
'entity',
'attribName',
'attribValue',
'cdata',
'script',
]

@@ -43,6 +55,6 @@

'opennamespace',
'closenamespace'
'closenamespace',
]
function SAXParser (strict, opt) {
function SAXParser(strict, opt) {
if (!(this instanceof SAXParser)) {

@@ -66,3 +78,6 @@ return new SAXParser(strict, opt)

parser.strictEntities = parser.opt.strictEntities
parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES)
parser.ENTITIES =
parser.strictEntities ?
Object.create(sax.XML_ENTITIES)
: Object.create(sax.ENTITIES)
parser.attribList = []

@@ -80,3 +95,3 @@

if (parser.opt.unquotedAttributeValues === undefined) {
parser.opt.unquotedAttributeValues = !strict;
parser.opt.unquotedAttributeValues = !strict
}

@@ -94,3 +109,3 @@

Object.create = function (o) {
function F () {}
function F() {}
F.prototype = o

@@ -110,3 +125,3 @@ var newf = new F()

function checkBufferLength (parser) {
function checkBufferLength(parser) {
var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)

@@ -147,3 +162,3 @@ var maxActual = 0

function clearBuffers (parser) {
function clearBuffers(parser) {
for (var i = 0, l = buffers.length; i < l; i++) {

@@ -154,3 +169,3 @@ parser[buffers[i]] = ''

function flushBuffers (parser) {
function flushBuffers(parser) {
closeText(parser)

@@ -168,7 +183,16 @@ if (parser.cdata !== '') {

SAXParser.prototype = {
end: function () { end(this) },
end: function () {
end(this)
},
write: write,
resume: function () { this.error = null; return this },
close: function () { return this.write(null) },
flush: function () { flushBuffers(this) }
resume: function () {
this.error = null
return this
},
close: function () {
return this.write(null)
},
flush: function () {
flushBuffers(this)
},
}

@@ -188,7 +212,7 @@

function createStream (strict, opt) {
function createStream(strict, opt) {
return new SAXStream(strict, opt)
}
function SAXStream (strict, opt) {
function SAXStream(strict, opt) {
if (!(this instanceof SAXStream)) {

@@ -234,3 +258,3 @@ return new SAXStream(strict, opt)

enumerable: true,
configurable: false
configurable: false,
})

@@ -242,10 +266,12 @@ })

constructor: {
value: SAXStream
}
value: SAXStream,
},
})
SAXStream.prototype.write = function (data) {
if (typeof Buffer === 'function' &&
if (
typeof Buffer === 'function' &&
typeof Buffer.isBuffer === 'function' &&
Buffer.isBuffer(data)) {
Buffer.isBuffer(data)
) {
if (!this._decoder) {

@@ -275,3 +301,6 @@ var SD = require('string_decoder').StringDecoder

me._parser['on' + ev] = function () {
var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments)
var args =
arguments.length === 1 ?
[arguments[0]]
: Array.apply(null, arguments)
args.splice(0, 0, ev)

@@ -299,26 +328,30 @@ me.emit.apply(me, args)

// is left as an exercise for the reader.
var nameStart = /[:_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]/
var nameStart =
/[:_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]/
var nameBody = /[:_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-]/
var nameBody =
/[:_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-]/
var entityStart = /[#:_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]/
var entityBody = /[#:_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-]/
var entityStart =
/[#:_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]/
var entityBody =
/[#:_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-]/
function isWhitespace (c) {
function isWhitespace(c) {
return c === ' ' || c === '\n' || c === '\r' || c === '\t'
}
function isQuote (c) {
return c === '"' || c === '\''
function isQuote(c) {
return c === '"' || c === "'"
}
function isAttribEnd (c) {
function isAttribEnd(c) {
return c === '>' || isWhitespace(c)
}
function isMatch (regex, c) {
function isMatch(regex, c) {
return regex.test(c)
}
function notMatch (regex, c) {
function notMatch(regex, c) {
return !isMatch(regex, c)

@@ -364,267 +397,267 @@ }

SCRIPT: S++, // <script> ...
SCRIPT_ENDING: S++ // <script> ... <
SCRIPT_ENDING: S++, // <script> ... <
}
sax.XML_ENTITIES = {
'amp': '&',
'gt': '>',
'lt': '<',
'quot': '"',
'apos': "'"
amp: '&',
gt: '>',
lt: '<',
quot: '"',
apos: "'",
}
sax.ENTITIES = {
'amp': '&',
'gt': '>',
'lt': '<',
'quot': '"',
'apos': "'",
'AElig': 198,
'Aacute': 193,
'Acirc': 194,
'Agrave': 192,
'Aring': 197,
'Atilde': 195,
'Auml': 196,
'Ccedil': 199,
'ETH': 208,
'Eacute': 201,
'Ecirc': 202,
'Egrave': 200,
'Euml': 203,
'Iacute': 205,
'Icirc': 206,
'Igrave': 204,
'Iuml': 207,
'Ntilde': 209,
'Oacute': 211,
'Ocirc': 212,
'Ograve': 210,
'Oslash': 216,
'Otilde': 213,
'Ouml': 214,
'THORN': 222,
'Uacute': 218,
'Ucirc': 219,
'Ugrave': 217,
'Uuml': 220,
'Yacute': 221,
'aacute': 225,
'acirc': 226,
'aelig': 230,
'agrave': 224,
'aring': 229,
'atilde': 227,
'auml': 228,
'ccedil': 231,
'eacute': 233,
'ecirc': 234,
'egrave': 232,
'eth': 240,
'euml': 235,
'iacute': 237,
'icirc': 238,
'igrave': 236,
'iuml': 239,
'ntilde': 241,
'oacute': 243,
'ocirc': 244,
'ograve': 242,
'oslash': 248,
'otilde': 245,
'ouml': 246,
'szlig': 223,
'thorn': 254,
'uacute': 250,
'ucirc': 251,
'ugrave': 249,
'uuml': 252,
'yacute': 253,
'yuml': 255,
'copy': 169,
'reg': 174,
'nbsp': 160,
'iexcl': 161,
'cent': 162,
'pound': 163,
'curren': 164,
'yen': 165,
'brvbar': 166,
'sect': 167,
'uml': 168,
'ordf': 170,
'laquo': 171,
'not': 172,
'shy': 173,
'macr': 175,
'deg': 176,
'plusmn': 177,
'sup1': 185,
'sup2': 178,
'sup3': 179,
'acute': 180,
'micro': 181,
'para': 182,
'middot': 183,
'cedil': 184,
'ordm': 186,
'raquo': 187,
'frac14': 188,
'frac12': 189,
'frac34': 190,
'iquest': 191,
'times': 215,
'divide': 247,
'OElig': 338,
'oelig': 339,
'Scaron': 352,
'scaron': 353,
'Yuml': 376,
'fnof': 402,
'circ': 710,
'tilde': 732,
'Alpha': 913,
'Beta': 914,
'Gamma': 915,
'Delta': 916,
'Epsilon': 917,
'Zeta': 918,
'Eta': 919,
'Theta': 920,
'Iota': 921,
'Kappa': 922,
'Lambda': 923,
'Mu': 924,
'Nu': 925,
'Xi': 926,
'Omicron': 927,
'Pi': 928,
'Rho': 929,
'Sigma': 931,
'Tau': 932,
'Upsilon': 933,
'Phi': 934,
'Chi': 935,
'Psi': 936,
'Omega': 937,
'alpha': 945,
'beta': 946,
'gamma': 947,
'delta': 948,
'epsilon': 949,
'zeta': 950,
'eta': 951,
'theta': 952,
'iota': 953,
'kappa': 954,
'lambda': 955,
'mu': 956,
'nu': 957,
'xi': 958,
'omicron': 959,
'pi': 960,
'rho': 961,
'sigmaf': 962,
'sigma': 963,
'tau': 964,
'upsilon': 965,
'phi': 966,
'chi': 967,
'psi': 968,
'omega': 969,
'thetasym': 977,
'upsih': 978,
'piv': 982,
'ensp': 8194,
'emsp': 8195,
'thinsp': 8201,
'zwnj': 8204,
'zwj': 8205,
'lrm': 8206,
'rlm': 8207,
'ndash': 8211,
'mdash': 8212,
'lsquo': 8216,
'rsquo': 8217,
'sbquo': 8218,
'ldquo': 8220,
'rdquo': 8221,
'bdquo': 8222,
'dagger': 8224,
'Dagger': 8225,
'bull': 8226,
'hellip': 8230,
'permil': 8240,
'prime': 8242,
'Prime': 8243,
'lsaquo': 8249,
'rsaquo': 8250,
'oline': 8254,
'frasl': 8260,
'euro': 8364,
'image': 8465,
'weierp': 8472,
'real': 8476,
'trade': 8482,
'alefsym': 8501,
'larr': 8592,
'uarr': 8593,
'rarr': 8594,
'darr': 8595,
'harr': 8596,
'crarr': 8629,
'lArr': 8656,
'uArr': 8657,
'rArr': 8658,
'dArr': 8659,
'hArr': 8660,
'forall': 8704,
'part': 8706,
'exist': 8707,
'empty': 8709,
'nabla': 8711,
'isin': 8712,
'notin': 8713,
'ni': 8715,
'prod': 8719,
'sum': 8721,
'minus': 8722,
'lowast': 8727,
'radic': 8730,
'prop': 8733,
'infin': 8734,
'ang': 8736,
'and': 8743,
'or': 8744,
'cap': 8745,
'cup': 8746,
'int': 8747,
'there4': 8756,
'sim': 8764,
'cong': 8773,
'asymp': 8776,
'ne': 8800,
'equiv': 8801,
'le': 8804,
'ge': 8805,
'sub': 8834,
'sup': 8835,
'nsub': 8836,
'sube': 8838,
'supe': 8839,
'oplus': 8853,
'otimes': 8855,
'perp': 8869,
'sdot': 8901,
'lceil': 8968,
'rceil': 8969,
'lfloor': 8970,
'rfloor': 8971,
'lang': 9001,
'rang': 9002,
'loz': 9674,
'spades': 9824,
'clubs': 9827,
'hearts': 9829,
'diams': 9830
amp: '&',
gt: '>',
lt: '<',
quot: '"',
apos: "'",
AElig: 198,
Aacute: 193,
Acirc: 194,
Agrave: 192,
Aring: 197,
Atilde: 195,
Auml: 196,
Ccedil: 199,
ETH: 208,
Eacute: 201,
Ecirc: 202,
Egrave: 200,
Euml: 203,
Iacute: 205,
Icirc: 206,
Igrave: 204,
Iuml: 207,
Ntilde: 209,
Oacute: 211,
Ocirc: 212,
Ograve: 210,
Oslash: 216,
Otilde: 213,
Ouml: 214,
THORN: 222,
Uacute: 218,
Ucirc: 219,
Ugrave: 217,
Uuml: 220,
Yacute: 221,
aacute: 225,
acirc: 226,
aelig: 230,
agrave: 224,
aring: 229,
atilde: 227,
auml: 228,
ccedil: 231,
eacute: 233,
ecirc: 234,
egrave: 232,
eth: 240,
euml: 235,
iacute: 237,
icirc: 238,
igrave: 236,
iuml: 239,
ntilde: 241,
oacute: 243,
ocirc: 244,
ograve: 242,
oslash: 248,
otilde: 245,
ouml: 246,
szlig: 223,
thorn: 254,
uacute: 250,
ucirc: 251,
ugrave: 249,
uuml: 252,
yacute: 253,
yuml: 255,
copy: 169,
reg: 174,
nbsp: 160,
iexcl: 161,
cent: 162,
pound: 163,
curren: 164,
yen: 165,
brvbar: 166,
sect: 167,
uml: 168,
ordf: 170,
laquo: 171,
not: 172,
shy: 173,
macr: 175,
deg: 176,
plusmn: 177,
sup1: 185,
sup2: 178,
sup3: 179,
acute: 180,
micro: 181,
para: 182,
middot: 183,
cedil: 184,
ordm: 186,
raquo: 187,
frac14: 188,
frac12: 189,
frac34: 190,
iquest: 191,
times: 215,
divide: 247,
OElig: 338,
oelig: 339,
Scaron: 352,
scaron: 353,
Yuml: 376,
fnof: 402,
circ: 710,
tilde: 732,
Alpha: 913,
Beta: 914,
Gamma: 915,
Delta: 916,
Epsilon: 917,
Zeta: 918,
Eta: 919,
Theta: 920,
Iota: 921,
Kappa: 922,
Lambda: 923,
Mu: 924,
Nu: 925,
Xi: 926,
Omicron: 927,
Pi: 928,
Rho: 929,
Sigma: 931,
Tau: 932,
Upsilon: 933,
Phi: 934,
Chi: 935,
Psi: 936,
Omega: 937,
alpha: 945,
beta: 946,
gamma: 947,
delta: 948,
epsilon: 949,
zeta: 950,
eta: 951,
theta: 952,
iota: 953,
kappa: 954,
lambda: 955,
mu: 956,
nu: 957,
xi: 958,
omicron: 959,
pi: 960,
rho: 961,
sigmaf: 962,
sigma: 963,
tau: 964,
upsilon: 965,
phi: 966,
chi: 967,
psi: 968,
omega: 969,
thetasym: 977,
upsih: 978,
piv: 982,
ensp: 8194,
emsp: 8195,
thinsp: 8201,
zwnj: 8204,
zwj: 8205,
lrm: 8206,
rlm: 8207,
ndash: 8211,
mdash: 8212,
lsquo: 8216,
rsquo: 8217,
sbquo: 8218,
ldquo: 8220,
rdquo: 8221,
bdquo: 8222,
dagger: 8224,
Dagger: 8225,
bull: 8226,
hellip: 8230,
permil: 8240,
prime: 8242,
Prime: 8243,
lsaquo: 8249,
rsaquo: 8250,
oline: 8254,
frasl: 8260,
euro: 8364,
image: 8465,
weierp: 8472,
real: 8476,
trade: 8482,
alefsym: 8501,
larr: 8592,
uarr: 8593,
rarr: 8594,
darr: 8595,
harr: 8596,
crarr: 8629,
lArr: 8656,
uArr: 8657,
rArr: 8658,
dArr: 8659,
hArr: 8660,
forall: 8704,
part: 8706,
exist: 8707,
empty: 8709,
nabla: 8711,
isin: 8712,
notin: 8713,
ni: 8715,
prod: 8719,
sum: 8721,
minus: 8722,
lowast: 8727,
radic: 8730,
prop: 8733,
infin: 8734,
ang: 8736,
and: 8743,
or: 8744,
cap: 8745,
cup: 8746,
int: 8747,
there4: 8756,
sim: 8764,
cong: 8773,
asymp: 8776,
ne: 8800,
equiv: 8801,
le: 8804,
ge: 8805,
sub: 8834,
sup: 8835,
nsub: 8836,
sube: 8838,
supe: 8839,
oplus: 8853,
otimes: 8855,
perp: 8869,
sdot: 8901,
lceil: 8968,
rceil: 8969,
lfloor: 8970,
rfloor: 8971,
lang: 9001,
rang: 9002,
loz: 9674,
spades: 9824,
clubs: 9827,
hearts: 9829,
diams: 9830,
}

@@ -645,7 +678,7 @@

function emit (parser, event, data) {
function emit(parser, event, data) {
parser[event] && parser[event](data)
}
function emitNode (parser, nodeType, data) {
function emitNode(parser, nodeType, data) {
if (parser.textNode) closeText(parser)

@@ -655,3 +688,3 @@ emit(parser, nodeType, data)

function closeText (parser) {
function closeText(parser) {
parser.textNode = textopts(parser.opt, parser.textNode)

@@ -662,3 +695,3 @@ if (parser.textNode) emit(parser, 'ontext', parser.textNode)

function textopts (opt, text) {
function textopts(opt, text) {
if (opt.trim) text = text.trim()

@@ -669,8 +702,12 @@ if (opt.normalize) text = text.replace(/\s+/g, ' ')

function error (parser, er) {
function error(parser, er) {
closeText(parser)
if (parser.trackPosition) {
er += '\nLine: ' + parser.line +
'\nColumn: ' + parser.column +
'\nChar: ' + parser.c
er +=
'\nLine: ' +
parser.line +
'\nColumn: ' +
parser.column +
'\nChar: ' +
parser.c
}

@@ -683,7 +720,10 @@ er = new Error(er)

function end (parser) {
if (parser.sawRoot && !parser.closedRoot) strictFail(parser, 'Unclosed root tag')
if ((parser.state !== S.BEGIN) &&
(parser.state !== S.BEGIN_WHITESPACE) &&
(parser.state !== S.TEXT)) {
function end(parser) {
if (parser.sawRoot && !parser.closedRoot)
strictFail(parser, 'Unclosed root tag')
if (
parser.state !== S.BEGIN &&
parser.state !== S.BEGIN_WHITESPACE &&
parser.state !== S.TEXT
) {
error(parser, 'Unexpected end')

@@ -699,3 +739,3 @@ }

function strictFail (parser, message) {
function strictFail(parser, message) {
if (typeof parser !== 'object' || !(parser instanceof SAXParser)) {

@@ -709,6 +749,6 @@ throw new Error('bad call to strictFail')

function newTag (parser) {
function newTag(parser) {
if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]()
var parent = parser.tags[parser.tags.length - 1] || parser
var tag = parser.tag = { name: parser.tagName, attributes: {} }
var tag = (parser.tag = { name: parser.tagName, attributes: {} })

@@ -723,5 +763,5 @@ // will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar"

function qname (name, attribute) {
function qname(name, attribute) {
var i = name.indexOf(':')
var qualName = i < 0 ? [ '', name ] : name.split(':')
var qualName = i < 0 ? ['', name] : name.split(':')
var prefix = qualName[0]

@@ -739,3 +779,3 @@ var local = qualName[1]

function attrib (parser) {
function attrib(parser) {
if (!parser.strict) {

@@ -745,4 +785,6 @@ parser.attribName = parser.attribName[parser.looseCase]()

if (parser.attribList.indexOf(parser.attribName) !== -1 ||
parser.tag.attributes.hasOwnProperty(parser.attribName)) {
if (
parser.attribList.indexOf(parser.attribName) !== -1 ||
parser.tag.attributes.hasOwnProperty(parser.attribName)
) {
parser.attribName = parser.attribValue = ''

@@ -760,9 +802,22 @@ return

if (local === 'xml' && parser.attribValue !== XML_NAMESPACE) {
strictFail(parser,
'xml: prefix must be bound to ' + XML_NAMESPACE + '\n' +
'Actual: ' + parser.attribValue)
} else if (local === 'xmlns' && parser.attribValue !== XMLNS_NAMESPACE) {
strictFail(parser,
'xmlns: prefix must be bound to ' + XMLNS_NAMESPACE + '\n' +
'Actual: ' + parser.attribValue)
strictFail(
parser,
'xml: prefix must be bound to ' +
XML_NAMESPACE +
'\n' +
'Actual: ' +
parser.attribValue,
)
} else if (
local === 'xmlns' &&
parser.attribValue !== XMLNS_NAMESPACE
) {
strictFail(
parser,
'xmlns: prefix must be bound to ' +
XMLNS_NAMESPACE +
'\n' +
'Actual: ' +
parser.attribValue,
)
} else {

@@ -787,3 +842,3 @@ var tag = parser.tag

name: parser.attribName,
value: parser.attribValue
value: parser.attribValue,
})

@@ -795,3 +850,3 @@ }

function openTag (parser, selfClosing) {
function openTag(parser, selfClosing) {
if (parser.opt.xmlns) {

@@ -808,4 +863,6 @@ // emit namespace binding events

if (tag.prefix && !tag.uri) {
strictFail(parser, 'Unbound namespace prefix: ' +
JSON.stringify(parser.tagName))
strictFail(
parser,
'Unbound namespace prefix: ' + JSON.stringify(parser.tagName),
)
tag.uri = qn.prefix

@@ -819,3 +876,3 @@ }

prefix: p,
uri: tag.ns[p]
uri: tag.ns[p],
})

@@ -835,3 +892,3 @@ })

var local = qualName.local
var uri = prefix === '' ? '' : (tag.ns[prefix] || '')
var uri = prefix === '' ? '' : tag.ns[prefix] || ''
var a = {

@@ -842,3 +899,3 @@ name: name,

local: local,
uri: uri
uri: uri,
}

@@ -849,4 +906,6 @@

if (prefix && prefix !== 'xmlns' && !uri) {
strictFail(parser, 'Unbound namespace prefix: ' +
JSON.stringify(prefix))
strictFail(
parser,
'Unbound namespace prefix: ' + JSON.stringify(prefix),
)
a.uri = prefix

@@ -880,3 +939,3 @@ }

function closeTag (parser) {
function closeTag(parser) {
if (!parser.tagName) {

@@ -928,3 +987,3 @@ strictFail(parser, 'Weird empty close tag.')

while (s-- > t) {
var tag = parser.tag = parser.tags.pop()
var tag = (parser.tag = parser.tags.pop())
parser.tagName = parser.tag.name

@@ -953,3 +1012,3 @@ emitNode(parser, 'onclosetag', parser.tagName)

function parseEntity (parser) {
function parseEntity(parser) {
var entity = parser.entity

@@ -987,3 +1046,3 @@ var entityLC = entity.toLowerCase()

function beginWhiteSpace (parser, c) {
function beginWhiteSpace(parser, c) {
if (c === '<') {

@@ -1001,3 +1060,3 @@ parser.state = S.OPEN_WAKA

function charAt (chunk, i) {
function charAt(chunk, i) {
var result = ''

@@ -1010,3 +1069,3 @@ if (i < chunk.length) {

function write (chunk) {
function write(chunk) {
var parser = this

@@ -1017,4 +1076,6 @@ if (this.error) {

if (parser.closed) {
return error(parser,
'Cannot write after close. Assign an onready handler.')
return error(
parser,
'Cannot write after close. Assign an onready handler.',
)
}

@@ -1077,7 +1138,13 @@ if (chunk === null) {

}
if (c === '<' && !(parser.sawRoot && parser.closedRoot && !parser.strict)) {
if (
c === '<' &&
!(parser.sawRoot && parser.closedRoot && !parser.strict)
) {
parser.state = S.OPEN_WAKA
parser.startTagPosition = parser.position
} else {
if (!isWhitespace(c) && (!parser.sawRoot || parser.closedRoot)) {
if (
!isWhitespace(c) &&
(!parser.sawRoot || parser.closedRoot)
) {
strictFail(parser, 'Text data outside of root node.')

@@ -1144,6 +1211,10 @@ }

parser.sgmlDecl = ''
continue;
continue
}
if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
if (
parser.doctype &&
parser.doctype !== true &&
parser.sgmlDecl
) {
parser.state = S.DOCTYPE_DTD

@@ -1160,4 +1231,6 @@ parser.doctype += '<!' + parser.sgmlDecl + c

if (parser.doctype || parser.sawRoot) {
strictFail(parser,
'Inappropriately located doctype declaration')
strictFail(
parser,
'Inappropriately located doctype declaration',
)
}

@@ -1271,6 +1344,18 @@ parser.doctype = ''

case S.CDATA:
var starti = i - 1
while (c && c !== ']') {
c = charAt(chunk, i++)
if (c && parser.trackPosition) {
parser.position++
if (c === '\n') {
parser.line++
parser.column = 0
} else {
parser.column++
}
}
}
parser.cdata += chunk.substring(starti, i - 1)
if (c === ']') {
parser.state = S.CDATA_ENDING
} else {
parser.cdata += c
}

@@ -1328,3 +1413,3 @@ continue

name: parser.procInstName,
body: parser.procInstBody
body: parser.procInstBody,
})

@@ -1362,3 +1447,6 @@ parser.procInstName = parser.procInstBody = ''

} else {
strictFail(parser, 'Forward-slash in opening tag not followed by >')
strictFail(
parser,
'Forward-slash in opening tag not followed by >',
)
parser.state = S.ATTRIB

@@ -1413,3 +1501,3 @@ }

name: parser.attribName,
value: ''
value: '',
})

@@ -1557,3 +1645,6 @@ parser.attribName = ''

var parsedEntity = parseEntity(parser)
if (parser.opt.unparsedEntities && !Object.values(sax.XML_ENTITIES).includes(parsedEntity)) {
if (
parser.opt.unparsedEntities &&
!Object.values(sax.XML_ENTITIES).includes(parsedEntity)
) {
parser.entity = ''

@@ -1567,3 +1658,5 @@ parser.state = returnState

}
} else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {
} else if (
isMatch(parser.entity.length ? entityBody : entityStart, c)
) {
parser.entity += c

@@ -1594,3 +1687,3 @@ } else {

if (!String.fromCodePoint) {
(function () {
;(function () {
var stringFromCharCode = String.fromCharCode

@@ -1614,3 +1707,3 @@ var floor = Math.floor

codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10FFFF || // not a valid Unicode code point
codePoint > 0x10ffff || // not a valid Unicode code point
floor(codePoint) !== codePoint // not an integer

@@ -1620,9 +1713,11 @@ ) {

}
if (codePoint <= 0xFFFF) { // BMP code point
if (codePoint <= 0xffff) {
// BMP code point
codeUnits.push(codePoint)
} else { // Astral code point; split in surrogate halves
} else {
// Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000
highSurrogate = (codePoint >> 10) + 0xD800
lowSurrogate = (codePoint % 0x400) + 0xDC00
highSurrogate = (codePoint >> 10) + 0xd800
lowSurrogate = (codePoint % 0x400) + 0xdc00
codeUnits.push(highSurrogate, lowSurrogate)

@@ -1642,3 +1737,3 @@ }

configurable: true,
writable: true
writable: true,
})

@@ -1648,4 +1743,4 @@ } else {

}
}())
})()
}
})(typeof exports === 'undefined' ? this.sax = {} : exports)
})(typeof exports === 'undefined' ? (this.sax = {}) : exports)

@@ -5,10 +5,11 @@ {

"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"version": "1.4.1",
"version": "1.4.2",
"main": "lib/sax.js",
"license": "ISC",
"license": "BlueOak-1.0.0",
"scripts": {
"test": "tap test/*.js --cov -j4",
"test": "tap",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
"postpublish": "git push origin --all; git push origin --tags",
"format": "prettier --write . --log-level warn"
},

@@ -22,10 +23,8 @@ "repository": "git://github.com/isaacs/sax-js.git",

"devDependencies": {
"tap": "^15.1.6"
"prettier": "^3.6.2",
"tap": "^21.1.3"
},
"tap": {
"statements": 79,
"branches": 75,
"functions": 80,
"lines": 79
"allow-incomplete-coverage": true
}
}
+42
-43

@@ -10,5 +10,5 @@ # sax js

* A very simple tool to parse through an XML string.
* A stepping stone to a streaming HTML parser.
* A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
- A very simple tool to parse through an XML string.
- A stepping stone to a streaming HTML parser.
- A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
docs.

@@ -18,14 +18,14 @@

* An HTML Parser - That's a fine goal, but this isn't it. It's just
- An HTML Parser - That's a fine goal, but this isn't it. It's just
XML.
* A DOM Builder - You can use it to build an object model out of XML,
- A DOM Builder - You can use it to build an object model out of XML,
but it doesn't do that out of the box.
* XSLT - No DOM = no querying.
* 100% Compliant with (some other SAX implementation) - Most SAX
- XSLT - No DOM = no querying.
- 100% Compliant with (some other SAX implementation) - Most SAX
implementations are in Java and do a lot more than this does.
* An XML Validator - It does a little validation when in strict mode, but
- An XML Validator - It does a little validation when in strict mode, but
not much.
* A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
- A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
masochism.
* A DTD-aware Thing - Fetching DTDs is a much bigger job.
- A DTD-aware Thing - Fetching DTDs is a much bigger job.

@@ -47,31 +47,31 @@ ## Regarding `<!DOCTYPE`s and `<!ENTITY`s

```javascript
var sax = require("./lib/sax"),
var sax = require('./lib/sax'),
strict = true, // set to false for html-mode
parser = sax.parser(strict);
parser = sax.parser(strict)
parser.onerror = function (e) {
// an error happened.
};
}
parser.ontext = function (t) {
// got some text. t is the string of text.
};
}
parser.onopentag = function (node) {
// opened a tag. node has "name" and "attributes"
};
}
parser.onattribute = function (attr) {
// an attribute. attr has "name" and "value"
};
}
parser.onend = function () {
// parser stream is done, and ready to have more stuff written to it.
};
}
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close()
// stream usage
// takes the same options as the parser
var saxStream = require("sax").createStream(strict, options)
saxStream.on("error", function (e) {
var saxStream = require('sax').createStream(strict, options)
saxStream.on('error', function (e) {
// unhandled errors will throw, since this is a proper node
// event emitter.
console.error("error!", e)
console.error('error!', e)
// clear the error

@@ -81,3 +81,3 @@ this._parser.error = null

})
saxStream.on("opentag", function (node) {
saxStream.on('opentag', function (node) {
// same object as above

@@ -87,29 +87,28 @@ })

// same chunks coming in also go out.
fs.createReadStream("file.xml")
fs.createReadStream('file.xml')
.pipe(saxStream)
.pipe(fs.createWriteStream("file-copy.xml"))
.pipe(fs.createWriteStream('file-copy.xml'))
```
## Arguments
Pass the following arguments to the parser function. All are optional.
Pass the following arguments to the parser function. All are optional.
`strict` - Boolean. Whether or not to be a jerk. Default: `false`.
`opt` - Object bag of settings regarding string formatting. All default to `false`.
`opt` - Object bag of settings regarding string formatting. All default to `false`.
Settings supported:
* `trim` - Boolean. Whether or not to trim text and comment nodes.
* `normalize` - Boolean. If true, then turn any whitespace into a single
- `trim` - Boolean. Whether or not to trim text and comment nodes.
- `normalize` - Boolean. If true, then turn any whitespace into a single
space.
* `lowercase` - Boolean. If true, then lowercase tag names and attribute names
- `lowercase` - Boolean. If true, then lowercase tag names and attribute names
in loose mode, rather than uppercasing them.
* `xmlns` - Boolean. If true, then namespaces are supported.
* `position` - Boolean. If false, then don't track line/col/position.
* `strictEntities` - Boolean. If true, only parse [predefined XML
- `xmlns` - Boolean. If true, then namespaces are supported.
- `position` - Boolean. If false, then don't track line/col/position.
- `strictEntities` - Boolean. If true, only parse [predefined XML
entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
(`&amp;`, `&apos;`, `&gt;`, `&lt;`, and `&quot;`)
* `unquotedAttributeValues` - Boolean. If true, then unquoted
- `unquotedAttributeValues` - Boolean. If true, then unquoted
attribute values are allowed. Defaults to `false` when `strict`

@@ -164,3 +163,3 @@ is true, `true` otherwise.

listening to this event, you can keep an eye on that kind of stuff. Note:
this happens *much* more in strict mode. Argument: instance of `Error`.
this happens _much_ more in strict mode. Argument: instance of `Error`.

@@ -181,4 +180,4 @@ `text` - Text node. Argument: string of text.

`opentagstart` - Emitted immediately when the tag name is available,
but before any attributes are encountered. Argument: object with a
`name` field and an empty `attributes` set. Note that this is the
but before any attributes are encountered. Argument: object with a
`name` field and an empty `attributes` set. Note that this is the
same object that will later be emitted in the `opentag` event.

@@ -188,3 +187,3 @@

In non-strict mode, tag names are uppercased, unless the `lowercase`
option is set. If the `xmlns` option is set, then it will contain
option is set. If the `xmlns` option is set, then it will contain
namespace binding information on the `ns` member, and will have a

@@ -198,8 +197,8 @@ `local`, `prefix`, and `uri` member.

`attribute` - An attribute node. Argument: object with `name` and `value`.
`attribute` - An attribute node. Argument: object with `name` and `value`.
In non-strict mode, attribute names are uppercased, unless the `lowercase`
option is set. If the `xmlns` option is set, it will also contains namespace
option is set. If the `xmlns` option is set, it will also contains namespace
information.
`comment` - A comment node. Argument: the string of the comment.
`comment` - A comment node. Argument: the string of the comment.

@@ -232,7 +231,7 @@ `opencdata` - The opening tag of a `<![CDATA[` block.

It's best to write a failing test if you find an issue. I will always
It's best to write a failing test if you find an issue. I will always
accept pull requests with failing tests if they demonstrate intended
behavior, but it is very hard to figure out what issue you're describing
without a test. Writing a test is also the best way for you yourself
without a test. Writing a test is also the best way for you yourself
to figure out if you really understand the issue you think you have with
sax-js.
The ISC License
Copyright (c) 2010-2024 Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
====
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT
License, as follows:
Copyright (c) 2010-2024 Mathias Bynens <https://mathiasbynens.be/>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.