diff --git a/package-lock.json b/package-lock.json index bcdb78f..0b7eab5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,7 @@ "version": "3.0.2", "license": "MPL-2.0", "dependencies": { - "@xmldom/xmldom": "^0.8.10", - "entities": "^4.5.0" + "@xmldom/xmldom": "^0.8.10" }, "devDependencies": { "@babel/cli": "^7.22.15", @@ -2990,17 +2989,6 @@ "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, "node_modules/es-abstract": { "version": "1.22.2", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.2.tgz", diff --git a/package.json b/package.json index 91b65d9..72d122a 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "typescript": "^5.2.2" }, "dependencies": { - "@xmldom/xmldom": "^0.8.10", - "entities": "^4.5.0" + "@xmldom/xmldom": "^0.8.10" } } diff --git a/src/util.ts b/src/util.ts index f46baee..d33afe4 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,3 @@ -import {decodeXML, encodeXML} from 'entities'; import {DOMParser} from '@xmldom/xmldom'; const numberLimit = 0x1fffffffffffff; @@ -16,26 +15,6 @@ export interface IElement { toString: () => string; } -/** - * Encode string for XML. - * - * @param value String value. - * @returns Escaped string. - */ -export function xmlEntitiesEncode(value: string) { - return encodeXML(value); -} - -/** - * Decode string for XML. - * - * @param value Encoded value. - * @returns Decoded string. - */ -export function xmlEntitiesDecode(value: string) { - return decodeXML(value); -} - /** * Decode an XML string. * diff --git a/src/value/dict.ts b/src/value/dict.ts index 7dcec63..bf98ef7 100644 --- a/src/value/dict.ts +++ b/src/value/dict.ts @@ -1,5 +1,5 @@ import {IToXmlOptioned} from '../options'; -import {IElement, xmlElementChildElements, xmlEntitiesEncode} from '../util'; +import {IElement, xmlElementChildElements} from '../util'; import {Value} from '../value'; import {ValueArray} from './array'; @@ -213,10 +213,11 @@ export class ValueDict extends Value { const p2 = optioned.indentString.repeat(depth + 1); const r = [`${p}`]; for (const [key, val] of v) { - r.push( - `${p2}${xmlEntitiesEncode(key)}`, - val.toXml(optioned, depth + 1) - ); + const e = key + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>'); + r.push(`${p2}${e}`, val.toXml(optioned, depth + 1)); } r.push(`${p}`); return r.join(optioned.newlineString); diff --git a/src/value/string.test.ts b/src/value/string.test.ts index 93f1497..8c1f281 100644 --- a/src/value/string.test.ts +++ b/src/value/string.test.ts @@ -28,12 +28,12 @@ void describe('value/string', () => { ); }); - void it('<&>', () => { - const el = new ValueString('<&>'); - strictEqual(el.toXml(), '<&>'); + void it(`<'"&"'>`, () => { + const el = new ValueString(`<'"&"'>`); + strictEqual(el.toXml(), `<'"&"'>`); strictEqual( el.toXml(null, 1), - '\t<&>' + `\t<'"&"'>` ); }); }); @@ -45,10 +45,10 @@ void describe('value/string', () => { strictEqual(el.value, 'hello world'); }); - void it('<&>', () => { + void it(`<'"&"'>`, () => { const el = new ValueString(''); - el.fromXml('<&>'); - strictEqual(el.value, '<&>'); + el.fromXml(`<'"&"'>`); + strictEqual(el.value, `<'"&"'>`); }); void it('empty', () => { diff --git a/src/value/string.ts b/src/value/string.ts index 290bd12..21c8489 100644 --- a/src/value/string.ts +++ b/src/value/string.ts @@ -1,5 +1,5 @@ import {IToXmlOptioned} from '../options'; -import {IElement, xmlEntitiesEncode} from '../util'; +import {IElement} from '../util'; import {Value} from '../value'; /** @@ -51,6 +51,10 @@ export class ValueString extends Value { */ protected _toXml(optioned: Readonly, depth: number) { const p = optioned.indentString.repeat(depth); - return `${p}${xmlEntitiesEncode(this.value)}`; + const e = this.value + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>'); + return `${p}${e}`; } }