xslt-processor
Advanced tools
Comparing version 0.9.2 to 0.10.0
{ | ||
"name": "xslt-processor", | ||
"version": "0.9.2", | ||
"version": "0.10.0", | ||
"description": "a JavaScript XSLT Processor", | ||
@@ -13,3 +13,12 @@ "main": "dist/xslt-processor.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "rollup src/index.js -f cjs -o dist/xslt-processor.js", | ||
"build": "rollup src/index.js -c -f cjs -o dist/xslt-processor.js", | ||
"build_tests": "npm run build_dom_unittests && npm run build_xmltoken_unittests && npm run build_xpath_unittests && npm run build_xpath_unittests2 && npm run build_xslt_unittest", | ||
"build_dom_unittests": "rollup tests_src/dom_unittest.js -c -f iife -o tests_dist/dom_unittest.js", | ||
"build_xmltoken_unittests": "rollup tests_src/xmltoken_unittest.js -c -f iife -o tests_dist/xmltoken_unittest.js", | ||
"build_xpath_unittests": "rollup tests_src/xpath_unittest.js -c -f iife --output.name xpath_unittest -o tests_dist/xpath_unittest.js", | ||
"build_xpath_unittests2": "rollup tests_src/xpath_unittest2.js -c -f iife -o tests_dist/xpath_unittest2.js", | ||
"build_xslt_unittest": "rollup tests_src/xslt_unittest.js -c -f iife -o tests_dist/xslt_unittest.js", | ||
"build_test": "npm run build_tests && npm run build_xpath_script && npm run build_xslt_script", | ||
"build_xpath_script": "rollup test_src/xpath_script.js -c -f iife -o test_dist/xpath_script.js", | ||
"build_xslt_script": "rollup test_src/xslt_script.js -c -f iife -o test_dist/xslt_script.js", | ||
"prepublish": "npm run build" | ||
@@ -31,4 +40,9 @@ }, | ||
"devDependencies": { | ||
"rollup": "^0.57.1" | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-commonjs": "^9.1.2" | ||
}, | ||
"dependencies": { | ||
"he": "^1.1.1" | ||
} | ||
} |
@@ -9,2 +9,4 @@ // Copyright 2018 Johannes Wilm | ||
// the subset of the W3C DOM that is used in the XSLT implementation. | ||
import he from "he" | ||
import { | ||
@@ -26,59 +28,4 @@ domSetAttribute, | ||
} from "./xmltoken.js" | ||
// Resolve entities in XML text fragments. According to the DOM | ||
// specification, the DOM is supposed to resolve entity references at | ||
// the API level. I.e. no entity references are passed through the | ||
// API. See "Entities and the DOM core", p.12, DOM 2 Core | ||
// Spec. However, different browsers actually pass very different | ||
// values at the API. See <http://mesch.nyc/test-xml-quote>. | ||
export function xmlResolveEntities(s) { | ||
const parts = s.split('&'); | ||
let ret = parts[0]; | ||
for (let i = 1; i < parts.length; ++i) { | ||
const rp = parts[i].indexOf(';'); | ||
if (rp == -1) { | ||
// no entity reference: just a & but no ; | ||
ret += parts[i]; | ||
continue; | ||
} | ||
const entityName = parts[i].substring(0, rp); | ||
const remainderText = parts[i].substring(rp + 1); | ||
let ch; | ||
switch (entityName) { | ||
case 'lt': | ||
ch = '<'; | ||
break; | ||
case 'gt': | ||
ch = '>'; | ||
break; | ||
case 'amp': | ||
ch = '&'; | ||
break; | ||
case 'quot': | ||
ch = '"'; | ||
break; | ||
case 'apos': | ||
ch = '\''; | ||
break; | ||
case 'nbsp': | ||
ch = String.fromCharCode(160); | ||
break; | ||
default: | ||
// Cool trick: let the DOM do the entity decoding. We assign | ||
// the entity text through non-W3C DOM properties and read it | ||
// through the W3C DOM. W3C DOM access is specified to resolve | ||
// entities. | ||
const span = domCreateElement(window.document, 'span'); | ||
span.innerHTML = `&${entityName}; `; | ||
ch = span.childNodes[0].nodeValue.charAt(0); | ||
} | ||
ret += ch + remainderText; | ||
} | ||
return ret; | ||
} | ||
const XML10_TAGNAME_REGEXP = new RegExp(`^(${XML10_NAME})`); | ||
@@ -151,3 +98,3 @@ const XML10_ATTRIBUTE_REGEXP = new RegExp(XML10_ATTRIBUTE, 'g'); | ||
while (att = regex_attribute.exec(text)) { | ||
const val = xmlResolveEntities(att[5] || att[7] || ''); | ||
const val = he.decode(att[5] || att[7] || ''); | ||
domSetAttribute(node, att[1], val); | ||
@@ -502,3 +449,3 @@ } | ||
constructor() { | ||
// NOTE(mesch): Acocording to the DOM Spec, ownerDocument of a | ||
// NOTE(mesch): According to the DOM Spec, ownerDocument of a | ||
// document node is null. | ||
@@ -505,0 +452,0 @@ super(DOM_DOCUMENT_NODE, '#document', null, null); |
@@ -11,24 +11,2 @@ // Copyright 2018 Johannes Wilm | ||
// Original author: Junji Takagi <jtakagi@google.com> | ||
// Detect whether RegExp supports Unicode characters or not. | ||
export const REGEXP_UNICODE = (() => { | ||
const tests = [' ', '\u0120', -1, // Konquerer 3.4.0 fails here. | ||
'!', '\u0120', -1, | ||
'\u0120', '\u0120', 0, | ||
'\u0121', '\u0120', -1, | ||
'\u0121', '\u0120|\u0121', 0, | ||
'\u0122', '\u0120|\u0121', -1, | ||
'\u0120', '[\u0120]', 0, // Safari 2.0.3 fails here. | ||
'\u0121', '[\u0120]', -1, | ||
'\u0121', '[\u0120\u0121]', 0, // Safari 2.0.3 fails here. | ||
'\u0122', '[\u0120\u0121]', -1, | ||
'\u0121', '[\u0120-\u0121]', 0, // Safari 2.0.3 fails here. | ||
'\u0122', '[\u0120-\u0121]', -1 | ||
]; | ||
for (let i = 0; i < tests.length; i += 3) { | ||
if (tests[i].search(new RegExp(tests[i + 1])) != tests[i + 2]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
})(); | ||
@@ -44,3 +22,3 @@ // Common tokens in XML 1.0 and XML 1.1. | ||
export const XML10_VERSION_INFO = `${XML_S}version${XML_EQ}("1\\.0"|'1\\.0')`; | ||
const XML10_BASE_CHAR = (REGEXP_UNICODE) ? | ||
const XML10_BASE_CHAR = | ||
'\u0041-\u005a\u0061-\u007a\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff' + | ||
@@ -79,8 +57,6 @@ '\u0100-\u0131\u0134-\u013e\u0141-\u0148\u014a-\u017e\u0180-\u01c3' + | ||
'\u1ff2-\u1ff4\u1ff6-\u1ffc\u2126\u212a-\u212b\u212e\u2180-\u2182' + | ||
'\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3' : | ||
'A-Za-z'; | ||
const XML10_IDEOGRAPHIC = (REGEXP_UNICODE) ? | ||
'\u4e00-\u9fa5\u3007\u3021-\u3029' : | ||
''; | ||
const XML10_COMBINING_CHAR = (REGEXP_UNICODE) ? | ||
'\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3'; | ||
const XML10_IDEOGRAPHIC = | ||
'\u4e00-\u9fa5\u3007\u3021-\u3029'; | ||
const XML10_COMBINING_CHAR = | ||
'\u0300-\u0345\u0360-\u0361\u0483-\u0486\u0591-\u05a1\u05a3-\u05b9' + | ||
@@ -100,13 +76,10 @@ '\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4\u064b-\u0652\u0670\u06d6-\u06dc' + | ||
'\u0f3e\u0f3f\u0f71-\u0f84\u0f86-\u0f8b\u0f90-\u0f95\u0f97\u0f99-\u0fad' + | ||
'\u0fb1-\u0fb7\u0fb9\u20d0-\u20dc\u20e1\u302a-\u302f\u3099\u309a' : | ||
''; | ||
const XML10_DIGIT = (REGEXP_UNICODE) ? | ||
'\u0fb1-\u0fb7\u0fb9\u20d0-\u20dc\u20e1\u302a-\u302f\u3099\u309a'; | ||
const XML10_DIGIT = | ||
'\u0030-\u0039\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef' + | ||
'\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be7-\u0bef\u0c66-\u0c6f' + | ||
'\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29' : | ||
'0-9'; | ||
const XML10_EXTENDER = (REGEXP_UNICODE) ? | ||
'\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29'; | ||
const XML10_EXTENDER = | ||
'\u00b7\u02d0\u02d1\u0387\u0640\u0e46\u0ec6\u3005\u3031-\u3035' + | ||
'\u309d-\u309e\u30fc-\u30fe' : | ||
''; | ||
'\u309d-\u309e\u30fc-\u30fe'; | ||
const XML10_LETTER = XML10_BASE_CHAR + XML10_IDEOGRAPHIC; | ||
@@ -130,9 +103,8 @@ const XML10_NAME_CHAR = `${XML10_LETTER + XML10_DIGIT}\\._:${XML10_COMBINING_CHAR}${XML10_EXTENDER}-`; | ||
export const XML11_VERSION_INFO = `${XML_S}version${XML_EQ}("1\\.1"|'1\\.1')`; | ||
const XML11_NAME_START_CHAR = (REGEXP_UNICODE) ? | ||
const XML11_NAME_START_CHAR = | ||
':A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d' + | ||
'\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff' + | ||
'\uf900-\ufdcf\ufdf0-\ufffd' : | ||
':A-Z_a-z'; | ||
'\uf900-\ufdcf\ufdf0-\ufffd'; | ||
const XML11_NAME_CHAR = XML11_NAME_START_CHAR + | ||
((REGEXP_UNICODE) ? '\\.0-9\u00b7\u0300-\u036f\u203f-\u2040-' : '\\.0-9-'); | ||
'\\.0-9\u00b7\u0300-\u036f\u203f-\u2040-'; | ||
export const XML11_NAME = `[${XML11_NAME_START_CHAR}][${XML11_NAME_CHAR}]*`; | ||
@@ -139,0 +111,0 @@ |
@@ -35,2 +35,4 @@ // Copyright 2018 Johannes Wilm | ||
// Original author: Steffen Meschkat <mesch@google.com> | ||
import he from "he" | ||
import { | ||
@@ -59,3 +61,2 @@ xmlValue, | ||
XDocument, | ||
xmlResolveEntities, | ||
DOM_DOCUMENT_NODE, | ||
@@ -546,3 +547,3 @@ DOM_DOCUMENT_FRAGMENT_NODE, | ||
// Wrapper function to access attribute values of template element | ||
// nodes. Currently this calls xmlResolveEntities because in some DOM | ||
// nodes. Currently this calls he.decode because in some DOM | ||
// implementations the return value of node.getAttributeValue() | ||
@@ -557,3 +558,3 @@ // contains unresolved XML entities, although the DOM spec requires | ||
if (value) { | ||
return xmlResolveEntities(value); | ||
return he.decode(value); | ||
} else { | ||
@@ -560,0 +561,0 @@ return value; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2103744
81
37926
1
3
1