Skip to content

Commit ca273dc

Browse files
committed
update strnum to support unicode, discard unsafe doctype entities
1 parent f589251 commit ca273dc

9 files changed

Lines changed: 404 additions & 327 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Note: Due to some last quick changes on v4, detail of v4.5.3 & v4.5.4 are not updated here. v4.5.4x is the last tag of v4 in github repository. I'm extremely sorry for the confusion
44

5+
**5.9.0* (not released yet)
6+
- update strnum to 2.3.0
7+
- you can set hex, binary, enotation, infinity, unicode
8+
- validate unsafe HTML or XML data in doctype entities unsing 'is-unsafe' library.
9+
User can override rules by overriding EntityDecoder.
10+
511
**5.8.0 / 2026-05-12*
612
- integrate xml-naming to validate DOCTYPE entity name and notation name (using qname becaue of backward compatibility)
713
- This will consider xml-version as well. '1.0' is default

lib/fxp.d.cts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,9 @@ type strnumOptions = {
509509
hex: boolean;
510510
leadingZeros: boolean,
511511
skipLike?: RegExp,
512-
eNotation?: boolean
512+
eNotation?: boolean,
513+
infinity?: string,
514+
unicode?: boolean
513515
}
514516

515517
type validationOptions = {

package-lock.json

Lines changed: 247 additions & 197 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@
8686
}
8787
],
8888
"dependencies": {
89-
"@nodable/entities": "^2.1.0",
89+
"@nodable/entities": "^2.2.0",
9090
"fast-xml-builder": "^1.2.0",
91+
"is-unsafe": "^1.0.1",
9192
"path-expression-matcher": "^1.5.0",
92-
"strnum": "^2.3.0",
93+
"strnum": "^2.4.0",
9394
"xml-naming": "^0.1.0"
9495
}
95-
}
96+
}

spec/temp.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ describe("unpaired and empty tags", function () {
2424
});
2525
fit("bug test", function () {
2626

27-
const xmlData = `<root><ns:code>safe <ns:code>nested</ns:code> still raw</ns:code></root>`;
28-
const options = {
29-
stopNodes: ["root.ns::code"],
30-
removeNSPrefix: true
31-
};
32-
33-
// const result = XMLValidator.validate(xmlData)
34-
const parser = new XMLParser(options);
35-
const result = parser.parse(xmlData);
36-
37-
console.log(result);
27+
const xml = `<?xml version="1.0"?>
28+
<!DOCTYPE foo [
29+
<!ENTITY lt "<script>alert(document.domain)</script>">
30+
]>
31+
<root>test &lt; value</root>`;
32+
33+
const result = new XMLParser().parse(xml);
34+
console.log(result.root);
3835
// console.log(JSON.stringify(result, null, 4));
3936
// expect(result).toEqual(expected);
4037

src/fxp.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,9 @@ export type strnumOptions = {
503503
hex: boolean;
504504
leadingZeros: boolean,
505505
skipLike?: RegExp,
506-
eNotation?: boolean
506+
eNotation?: boolean,
507+
infinity?: string,
508+
unicode?: boolean
507509
}
508510

509511
export type validationOptions = {

src/xmlparser/OptionsBuilder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const defaultOptions = {
2525
numberParseOptions: {
2626
hex: true,
2727
leadingZeros: true,
28-
eNotation: true
28+
eNotation: true,
29+
unicode: false
2930
},
3031
tagValueProcessor: function (tagName, val) {
3132
return val;

src/xmlparser/OrderedObjParser.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import toNumber from "strnum";
88
import getIgnoreAttributesFn from "../ignoreAttributes.js";
99
import { Expression, Matcher } from 'path-expression-matcher';
1010
import { ExpressionSet } from 'path-expression-matcher';
11-
import { EntityDecoder, XML, CURRENCY, COMMON_HTML } from '@nodable/entities';
11+
import { EntityDecoder, XML, CURRENCY, COMMON_HTML, ENTITY_ACTION } from '@nodable/entities';
12+
import { isUnsafe, VALID_CONTEXTS } from "is-unsafe"
13+
1214

1315
// const regx =
1416
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
@@ -98,7 +100,12 @@ export default class OrderedObjParser {
98100
maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
99101
maxExpandedLength: this.options.processEntities.maxExpandedLength,
100102
applyLimitsTo: this.options.processEntities.appliesTo,
101-
}
103+
},
104+
// onExternalEntity: (name, value) => isUnsafe(value) ? 'block' : 'allow',
105+
onInputEntity: (name, value) =>
106+
isUnsafe(value, [VALID_CONTEXTS.HTML, VALID_CONTEXTS.XML])
107+
? ENTITY_ACTION.BLOCK : ENTITY_ACTION.ALLOW,
108+
102109
//postCheck: resolved => resolved
103110
});
104111
}

0 commit comments

Comments
 (0)