Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

saxen

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

saxen - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

8

CHANGELOG.md

@@ -0,1 +1,9 @@

# 1.0.2
* `FIX`: properly handle namespace prefix collisions [#1](https://github.com/nikku/saxen/issues/1)
# 1.0.1
* `CHORE`: improve test coverage and documentation
# 1.0.0

@@ -2,0 +10,0 @@

2

package.json

@@ -16,3 +16,3 @@ {

],
"version": "1.0.1",
"version": "1.0.2",
"main": "./parser.js",

@@ -19,0 +19,0 @@ "bugs": {

@@ -69,9 +69,27 @@ 'use strict';

function cloneNsMatrix(nsMatrix) {
var nn = {}, n;
for (n in nsMatrix) {
nn[n] = nsMatrix[n];
var clone = {}, key;
for (key in nsMatrix) {
clone[key] = nsMatrix[key];
}
return nn;
return clone;
}
function uriPrefix(prefix) {
return prefix + '$uri';
}
function buildNsMatrix(nsUriToPrefix) {
var nsMatrix = {},
uri,
prefix;
for (uri in nsUriToPrefix) {
prefix = nsUriToPrefix[uri];
nsMatrix[prefix] = prefix;
nsMatrix[uriPrefix(prefix)] = uri;
}
return nsMatrix;
}
function noopGetContext() { return { line: 0, column: 0 }; }

@@ -111,8 +129,41 @@

/**
* Do we need to parse the current elements attributes for namespaces?
*
* @type {Boolean}
*/
var maybeNS = false;
/**
* Do we process namespaces at all?
*
* @type {Boolean}
*/
var isNamespace = false;
/**
* The caught error returned on parse end
*
* @type {Error}
*/
var returnError = null;
/**
* Should we stop parsing?
*
* @type {Boolean}
*/
var parseStop = false; // прервать парсер
var useNS;
/**
* A map of { uri: prefix } used by the parser.
*
* This map will ensure we can normalize prefixes during processing;
* for each uri, only one prefix will be exposed to the handlers.
*
* @type {Object}
*/
var nsUriToPrefix;
function failSafe(cb, onError) {

@@ -197,10 +248,10 @@ return function() {

var _useNS = {}, k;
var _nsUriToPrefix = {}, k;
for (k in nsMap) {
_useNS[k] = nsMap[k];
_nsUriToPrefix[k] = nsMap[k];
}
isNamespace = true;
useNS = _useNS;
nsUriToPrefix = _nsUriToPrefix;

@@ -248,3 +299,3 @@ return this;

nsMatrixStack = isNamespace ? [] : null,
nsMatrix = isNamespace ? {} : null,
nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
_nsMatrix,

@@ -284,2 +335,4 @@ nodeStack = [],

var nsAttrName,
nsUri,
nsUriPrefix,
attrList = isNamespace && maybeNS ? [] : null,

@@ -385,7 +438,17 @@ i = attrsStart,

if (newalias !== null) {
alias = useNS[decodeEntities(value)];
nsUri = decodeEntities(value);
nsUriPrefix = uriPrefix(newalias);
alias = nsUriToPrefix[nsUri];
if (!alias) {
if (newalias === 'xmlns') {
alias = 'ns' + (anonymousNsCount++);
// no prefix defined or prefix collision
if (
(newalias === 'xmlns') ||
(nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
) {
// alocate free ns prefix
do {
alias = 'ns' + (anonymousNsCount++);
} while (typeof nsMatrix[alias] !== 'undefined');
} else {

@@ -395,3 +458,3 @@ alias = newalias;

useNS[decodeEntities(value)] = alias;
nsUriToPrefix[nsUri] = alias;
}

@@ -406,2 +469,7 @@

nsMatrix[newalias] = alias;
if (newalias === 'xmlns') {
nsMatrix[uriPrefix(alias)] = nsUri;
}
nsMatrix[nsUriPrefix] = nsUri;
}

@@ -408,0 +476,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc