@cdklabs/cdk-ecs-codedeploy 0.0.431 → 0.0.432
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +3 -3
- package/.jsii.tabl.json +1 -1
- package/lib/api-canary/index.js +1 -1
- package/lib/ecs-appspec/index.js +1 -1
- package/lib/ecs-deployment/index.js +1 -1
- package/lib/ecs-patterns/application-load-balanced-codedeployed-fargate-service.js +1 -1
- package/node_modules/@aws-sdk/client-codedeploy/package.json +38 -38
- package/node_modules/@aws-sdk/core/dist-cjs/index.js +7 -15
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +7 -15
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +2 -8
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeDeserializer.js +5 -7
- package/node_modules/@aws-sdk/core/package.json +13 -13
- package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-http/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +14 -14
- package/node_modules/@aws-sdk/credential-provider-login/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +7 -7
- package/node_modules/@aws-sdk/middleware-host-header/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-logger/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/index.js +9 -9
- package/node_modules/@aws-sdk/middleware-user-agent/dist-es/check-features.js +9 -9
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/check-features.d.ts +4 -2
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/ts3.4/check-features.d.ts +3 -3
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +8 -7
- package/node_modules/@aws-sdk/nested-clients/package.json +38 -36
- package/node_modules/@aws-sdk/region-config-resolver/package.json +5 -5
- package/node_modules/@aws-sdk/token-providers/package.json +7 -7
- package/node_modules/@aws-sdk/types/package.json +2 -2
- package/node_modules/@aws-sdk/util-endpoints/package.json +5 -5
- package/node_modules/@aws-sdk/util-locate-window/package.json +2 -2
- package/node_modules/@aws-sdk/util-user-agent-browser/package.json +3 -3
- package/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js +36 -19
- package/node_modules/@aws-sdk/util-user-agent-node/dist-es/getSanitizedTypeScriptVersion.js +9 -0
- package/node_modules/@aws-sdk/util-user-agent-node/dist-es/getTypeScriptPackageJsonPaths.js +17 -0
- package/node_modules/@aws-sdk/util-user-agent-node/dist-es/getTypeScriptUserAgentPair.js +17 -12
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/getSanitizedTypeScriptVersion.d.ts +8 -0
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/getTypeScriptPackageJsonPaths.d.ts +10 -0
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/ts3.4/getSanitizedTypeScriptVersion.d.ts +3 -0
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/ts3.4/getTypeScriptPackageJsonPaths.d.ts +3 -0
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +5 -5
- package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.js +1 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js +1 -0
- package/node_modules/@aws-sdk/xml-builder/package.json +3 -3
- package/node_modules/@smithy/abort-controller/package.json +2 -2
- package/node_modules/@smithy/config-resolver/package.json +6 -6
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +2 -8
- package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +1 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +1 -1
- package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +2 -8
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +1 -1
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +1 -1
- package/node_modules/@smithy/core/package.json +11 -11
- package/node_modules/@smithy/credential-provider-imds/package.json +5 -5
- package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +18 -4
- package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +18 -4
- package/node_modules/@smithy/fetch-http-handler/package.json +6 -6
- package/node_modules/@smithy/hash-node/package.json +4 -4
- package/node_modules/@smithy/invalid-dependency/package.json +2 -2
- package/node_modules/@smithy/is-array-buffer/package.json +2 -2
- package/node_modules/@smithy/middleware-content-length/package.json +3 -3
- package/node_modules/@smithy/middleware-endpoint/package.json +8 -8
- package/node_modules/@smithy/middleware-retry/package.json +9 -9
- package/node_modules/@smithy/middleware-serde/package.json +3 -3
- package/node_modules/@smithy/middleware-stack/package.json +2 -2
- package/node_modules/@smithy/node-config-provider/package.json +4 -4
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +21 -8
- package/node_modules/@smithy/node-http-handler/dist-es/build-abort-error.js +16 -0
- package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +3 -4
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +3 -4
- package/node_modules/@smithy/node-http-handler/dist-types/build-abort-error.d.ts +9 -0
- package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/build-abort-error.d.ts +9 -0
- package/node_modules/@smithy/node-http-handler/package.json +5 -5
- package/node_modules/@smithy/property-provider/package.json +2 -2
- package/node_modules/@smithy/protocol-http/package.json +2 -2
- package/node_modules/@smithy/querystring-builder/package.json +3 -3
- package/node_modules/@smithy/querystring-parser/package.json +2 -2
- package/node_modules/@smithy/service-error-classification/package.json +2 -2
- package/node_modules/@smithy/shared-ini-file-loader/package.json +2 -2
- package/node_modules/@smithy/signature-v4/package.json +8 -8
- package/node_modules/@smithy/smithy-client/package.json +7 -7
- package/node_modules/@smithy/url-parser/package.json +3 -3
- package/node_modules/@smithy/util-base64/package.json +4 -4
- package/node_modules/@smithy/util-body-length-browser/package.json +2 -2
- package/node_modules/@smithy/util-body-length-node/package.json +2 -2
- package/node_modules/@smithy/util-buffer-from/package.json +3 -3
- package/node_modules/@smithy/util-config-provider/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +4 -4
- package/node_modules/@smithy/util-defaults-mode-node/package.json +7 -7
- package/node_modules/@smithy/util-endpoints/package.json +3 -3
- package/node_modules/@smithy/util-hex-encoding/package.json +2 -2
- package/node_modules/@smithy/util-middleware/package.json +2 -2
- package/node_modules/@smithy/util-retry/package.json +3 -3
- package/node_modules/@smithy/util-stream/package.json +8 -8
- package/node_modules/@smithy/util-uri-escape/package.json +2 -2
- package/node_modules/@smithy/util-utf8/package.json +3 -3
- package/node_modules/@smithy/util-waiter/package.json +3 -3
- package/node_modules/@smithy/uuid/package.json +2 -2
- package/node_modules/fast-xml-builder/LICENSE +21 -0
- package/node_modules/fast-xml-builder/README.md +23 -0
- package/node_modules/fast-xml-builder/lib/builder.cjs +1 -0
- package/node_modules/fast-xml-builder/lib/builder.min.js +2 -0
- package/node_modules/fast-xml-builder/lib/builder.min.js.map +1 -0
- package/node_modules/fast-xml-builder/lib/fxb.d.cts +167 -0
- package/node_modules/fast-xml-builder/package.json +78 -0
- package/node_modules/fast-xml-builder/src/fxb.d.ts +156 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js → fast-xml-builder/src/fxb.js} +50 -50
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlbuilder → fast-xml-builder/src}/orderedJs2Xml.js +14 -3
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/CHANGELOG.md +23 -0
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/lib/fxp.d.cts +15 -1
- package/node_modules/fast-xml-parser/lib/fxp.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxparser.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +1 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/package.json +3 -2
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/fxp.d.ts +16 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/fxp.js +1 -1
- package/node_modules/fast-xml-parser/src/ignoreAttributes.js +18 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/util.js +1 -26
- package/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +106 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OptionsBuilder.js +10 -10
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OutputBuilders/BaseOutputBuilder.js +23 -23
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OutputBuilders/JsArrBuilder.js +29 -29
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OutputBuilders/JsObjBuilder.js +39 -39
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OutputBuilders/ParserOptionsBuilder.js +17 -17
- package/node_modules/fast-xml-parser/src/v6/Report.js +0 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/XMLParser.js +22 -22
- package/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +105 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/validator.js +34 -34
- package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +6 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/DocTypeReader.js +1 -1
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/OptionsBuilder.js +2 -0
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/OrderedObjParser.js +27 -5
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/XMLParser.js +21 -21
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/node2json.js +38 -34
- package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/xmlparser/xmlNode.js +10 -10
- package/package.json +6 -6
- package/node_modules/@aws-sdk/util-user-agent-node/dist-es/getTypeScriptPackageJsonPath.js +0 -14
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/getTypeScriptPackageJsonPath.d.ts +0 -9
- package/node_modules/@aws-sdk/util-user-agent-node/dist-types/ts3.4/getTypeScriptPackageJsonPath.d.ts +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.cjs +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js.map +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js.map +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js +0 -2
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +0 -1
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +0 -106
- package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +0 -105
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/Report.js → fast-xml-builder/CHANGELOG.md} +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-builder}/src/ignoreAttributes.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlbuilder → fast-xml-builder/src}/prettifyJs2Xml.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/LICENSE +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/README.md +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/cli/cli.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/cli/man.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/cli/read.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/CharsSymbol.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/OutputBuilders/JsMinArrBuilder.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/TagPath.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/TagPathMatcher.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/Xml2JsParser.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/XmlPartReader.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/XmlSpecialTagsReader.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/inputSource/BufferSource.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/inputSource/StringSource.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/booleanParser.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/booleanParserExt.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/currency.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/join.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/number.js +0 -0
- /package/node_modules/{@aws-sdk/xml-builder/node_modules/fast-xml-parser → fast-xml-parser}/src/v6/valueParsers/trim.js +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
2
|
+
const htmlEntities = {
|
|
3
|
+
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
4
|
+
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
5
|
+
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
6
|
+
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
7
|
+
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
8
|
+
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
9
|
+
"cent": { regex: /&(cent|#162);/g, val: "¢" },
|
|
10
|
+
"pound": { regex: /&(pound|#163);/g, val: "£" },
|
|
11
|
+
"yen": { regex: /&(yen|#165);/g, val: "¥" },
|
|
12
|
+
"euro": { regex: /&(euro|#8364);/g, val: "€" },
|
|
13
|
+
"copyright": { regex: /&(copy|#169);/g, val: "©" },
|
|
14
|
+
"reg": { regex: /&(reg|#174);/g, val: "®" },
|
|
15
|
+
"inr": { regex: /&(inr|#8377);/g, val: "₹" },
|
|
16
|
+
"num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },
|
|
17
|
+
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default class EntitiesParser {
|
|
21
|
+
constructor(replaceHtmlEntities) {
|
|
22
|
+
this.replaceHtmlEntities = replaceHtmlEntities;
|
|
23
|
+
this.docTypeEntities = {};
|
|
24
|
+
this.lastEntities = {
|
|
25
|
+
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
26
|
+
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
27
|
+
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
28
|
+
"quot": { regex: /&(quot|#34|#x22);/g, val: "\"" },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
addExternalEntities(externalEntities) {
|
|
33
|
+
const entKeys = Object.keys(externalEntities);
|
|
34
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
35
|
+
const ent = entKeys[i];
|
|
36
|
+
this.addExternalEntity(ent, externalEntities[ent])
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
addExternalEntity(key, val) {
|
|
40
|
+
validateEntityName(key);
|
|
41
|
+
if (val.indexOf("&") !== -1) {
|
|
42
|
+
reportWarning(`Entity ${key} is not added as '&' is found in value;`)
|
|
43
|
+
return;
|
|
44
|
+
} else {
|
|
45
|
+
this.lastEntities[ent] = {
|
|
46
|
+
regex: new RegExp("&" + key + ";", "g"),
|
|
47
|
+
val: val
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addDocTypeEntities(entities) {
|
|
53
|
+
const entKeys = Object.keys(entities);
|
|
54
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
55
|
+
const ent = entKeys[i];
|
|
56
|
+
this.docTypeEntities[ent] = {
|
|
57
|
+
regex: new RegExp("&" + ent + ";", "g"),
|
|
58
|
+
val: entities[ent]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
parse(val) {
|
|
64
|
+
return this.replaceEntitiesValue(val)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 1. Replace DOCTYPE entities
|
|
69
|
+
* 2. Replace external entities
|
|
70
|
+
* 3. Replace HTML entities if asked
|
|
71
|
+
* @param {string} val
|
|
72
|
+
*/
|
|
73
|
+
replaceEntitiesValue(val) {
|
|
74
|
+
if (typeof val === "string" && val.length > 0) {
|
|
75
|
+
for (let entityName in this.docTypeEntities) {
|
|
76
|
+
const entity = this.docTypeEntities[entityName];
|
|
77
|
+
val = val.replace(entity.regx, entity.val);
|
|
78
|
+
}
|
|
79
|
+
for (let entityName in this.lastEntities) {
|
|
80
|
+
const entity = this.lastEntities[entityName];
|
|
81
|
+
val = val.replace(entity.regex, entity.val);
|
|
82
|
+
}
|
|
83
|
+
if (this.replaceHtmlEntities) {
|
|
84
|
+
for (let entityName in htmlEntities) {
|
|
85
|
+
const entity = htmlEntities[entityName];
|
|
86
|
+
val = val.replace(entity.regex, entity.val);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
val = val.replace(ampEntity.regex, ampEntity.val);
|
|
90
|
+
}
|
|
91
|
+
return val;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//an entity name should not contains special characters that may be used in regex
|
|
96
|
+
//Eg !?\\\/[]$%{}^&*()<>
|
|
97
|
+
const specialChar = "!?\\\/[]$%{}^&*()<>|+";
|
|
98
|
+
|
|
99
|
+
function validateEntityName(name) {
|
|
100
|
+
for (let i = 0; i < specialChar.length; i++) {
|
|
101
|
+
const ch = specialChar[i];
|
|
102
|
+
if (name.indexOf(ch) !== -1) throw new Error(`Invalid character ${ch} in entity name`);
|
|
103
|
+
}
|
|
104
|
+
return name;
|
|
105
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import {getAllMatches, isName} from './util.js';
|
|
3
|
+
import { getAllMatches, isName } from './util.js';
|
|
4
4
|
|
|
5
5
|
const defaultOptions = {
|
|
6
6
|
allowBooleanAttributes: false, //A tag can have attributes without any value
|
|
@@ -24,19 +24,19 @@ export function validate(xmlData, options) {
|
|
|
24
24
|
// check for byte order mark (BOM)
|
|
25
25
|
xmlData = xmlData.substr(1);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
for (let i = 0; i < xmlData.length; i++) {
|
|
29
29
|
|
|
30
|
-
if (xmlData[i] === '<' && xmlData[i+1] === '?') {
|
|
31
|
-
i+=2;
|
|
32
|
-
i = readPI(xmlData,i);
|
|
30
|
+
if (xmlData[i] === '<' && xmlData[i + 1] === '?') {
|
|
31
|
+
i += 2;
|
|
32
|
+
i = readPI(xmlData, i);
|
|
33
33
|
if (i.err) return i;
|
|
34
|
-
}else if (xmlData[i] === '<') {
|
|
34
|
+
} else if (xmlData[i] === '<') {
|
|
35
35
|
//starting of tag
|
|
36
36
|
//read until you reach to '>' avoiding any '>' in attribute value
|
|
37
37
|
let tagStartPos = i;
|
|
38
38
|
i++;
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
if (xmlData[i] === '!') {
|
|
41
41
|
i = readCommentAndCDATA(xmlData, i);
|
|
42
42
|
continue;
|
|
@@ -72,14 +72,14 @@ export function validate(xmlData, options) {
|
|
|
72
72
|
if (tagName.trim().length === 0) {
|
|
73
73
|
msg = "Invalid space after '<'.";
|
|
74
74
|
} else {
|
|
75
|
-
msg = "Tag '"+tagName+"' is an invalid name.";
|
|
75
|
+
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
76
76
|
}
|
|
77
77
|
return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
const result = readAttributeStr(xmlData, i);
|
|
81
81
|
if (result === false) {
|
|
82
|
-
return getErrorObject('InvalidAttr', "Attributes for '"+tagName+"' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
82
|
+
return getErrorObject('InvalidAttr', "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
83
83
|
}
|
|
84
84
|
let attrStr = result.value;
|
|
85
85
|
i = result.index;
|
|
@@ -100,17 +100,17 @@ export function validate(xmlData, options) {
|
|
|
100
100
|
}
|
|
101
101
|
} else if (closingTag) {
|
|
102
102
|
if (!result.tagClosed) {
|
|
103
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
103
|
+
return getErrorObject('InvalidTag', "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
104
104
|
} else if (attrStr.trim().length > 0) {
|
|
105
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
105
|
+
return getErrorObject('InvalidTag', "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
106
106
|
} else if (tags.length === 0) {
|
|
107
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
107
|
+
return getErrorObject('InvalidTag', "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
108
108
|
} else {
|
|
109
109
|
const otg = tags.pop();
|
|
110
110
|
if (tagName !== otg.tagName) {
|
|
111
111
|
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
112
112
|
return getErrorObject('InvalidTag',
|
|
113
|
-
"Expected closing tag '"+otg.tagName+"' (opened in line "+openPos.line+", col "+openPos.col+") instead of closing tag '"+tagName+"'.",
|
|
113
|
+
"Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
|
|
114
114
|
getLineNumberForPosition(xmlData, tagStartPos));
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -131,10 +131,10 @@ export function validate(xmlData, options) {
|
|
|
131
131
|
//if the root level has been reached before ...
|
|
132
132
|
if (reachedRoot === true) {
|
|
133
133
|
return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
|
|
134
|
-
} else if(options.unpairedTags.indexOf(tagName) !== -1){
|
|
134
|
+
} else if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
135
135
|
//don't push into stack
|
|
136
136
|
} else {
|
|
137
|
-
tags.push({tagName, tagStartPos});
|
|
137
|
+
tags.push({ tagName, tagStartPos });
|
|
138
138
|
}
|
|
139
139
|
tagFound = true;
|
|
140
140
|
}
|
|
@@ -148,10 +148,10 @@ export function validate(xmlData, options) {
|
|
|
148
148
|
i++;
|
|
149
149
|
i = readCommentAndCDATA(xmlData, i);
|
|
150
150
|
continue;
|
|
151
|
-
} else if (xmlData[i+1] === '?') {
|
|
151
|
+
} else if (xmlData[i + 1] === '?') {
|
|
152
152
|
i = readPI(xmlData, ++i);
|
|
153
153
|
if (i.err) return i;
|
|
154
|
-
} else{
|
|
154
|
+
} else {
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
} else if (xmlData[i] === '&') {
|
|
@@ -159,7 +159,7 @@ export function validate(xmlData, options) {
|
|
|
159
159
|
if (afterAmp == -1)
|
|
160
160
|
return getErrorObject('InvalidChar', "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
161
161
|
i = afterAmp;
|
|
162
|
-
}else{
|
|
162
|
+
} else {
|
|
163
163
|
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
164
164
|
return getErrorObject('InvalidXml', "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
165
165
|
}
|
|
@@ -170,28 +170,28 @@ export function validate(xmlData, options) {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
} else {
|
|
173
|
-
if (
|
|
173
|
+
if (isWhiteSpace(xmlData[i])) {
|
|
174
174
|
continue;
|
|
175
175
|
}
|
|
176
|
-
return getErrorObject('InvalidChar', "char '"+xmlData[i]+"' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
176
|
+
return getErrorObject('InvalidChar', "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
if (!tagFound) {
|
|
181
181
|
return getErrorObject('InvalidXml', 'Start tag expected.', 1);
|
|
182
|
-
}else if (tags.length == 1) {
|
|
183
|
-
|
|
184
|
-
}else if (tags.length > 0) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
} else if (tags.length == 1) {
|
|
183
|
+
return getErrorObject('InvalidTag', "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
184
|
+
} else if (tags.length > 0) {
|
|
185
|
+
return getErrorObject('InvalidXml', "Invalid '" +
|
|
186
|
+
JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\r?\n/g, '') +
|
|
187
|
+
"' found.", { line: 1, col: 1 });
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
return true;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
function isWhiteSpace(char){
|
|
194
|
-
return char === ' ' || char === '\t' || char === '\n'
|
|
193
|
+
function isWhiteSpace(char) {
|
|
194
|
+
return char === ' ' || char === '\t' || char === '\n' || char === '\r';
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
197
|
* Read Processing insstructions and skip
|
|
@@ -327,25 +327,25 @@ function validateAttributeString(attrStr, options) {
|
|
|
327
327
|
for (let i = 0; i < matches.length; i++) {
|
|
328
328
|
if (matches[i][1].length === 0) {
|
|
329
329
|
//nospace before attribute name: a="sd"b="saf"
|
|
330
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(matches[i]))
|
|
330
|
+
return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]))
|
|
331
331
|
} else if (matches[i][3] !== undefined && matches[i][4] === undefined) {
|
|
332
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' is without value.", getPositionFromMatch(matches[i]));
|
|
332
|
+
return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
333
333
|
} else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
|
|
334
334
|
//independent attribute: ab
|
|
335
|
-
return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(matches[i]));
|
|
335
|
+
return getErrorObject('InvalidAttr', "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
336
336
|
}
|
|
337
337
|
/* else if(matches[i][6] === undefined){//attribute without value: ab=
|
|
338
338
|
return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
|
|
339
339
|
} */
|
|
340
340
|
const attrName = matches[i][2];
|
|
341
341
|
if (!validateAttrName(attrName)) {
|
|
342
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
342
|
+
return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
343
343
|
}
|
|
344
|
-
if (!
|
|
344
|
+
if (!Object.prototype.hasOwnProperty.call(attrNames, attrName)) {
|
|
345
345
|
//check for duplicate attribute.
|
|
346
346
|
attrNames[attrName] = 1;
|
|
347
347
|
} else {
|
|
348
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(matches[i]));
|
|
348
|
+
return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
|
|
@@ -163,6 +163,7 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
163
163
|
aName = this.options.transformAttributeName(aName);
|
|
164
164
|
}
|
|
165
165
|
if (aName === "__proto__") aName = "#__proto__";
|
|
166
|
+
|
|
166
167
|
if (oldVal !== undefined) {
|
|
167
168
|
if (this.options.trimValues) {
|
|
168
169
|
oldVal = oldVal.trim();
|
|
@@ -322,6 +323,13 @@ const parseXml = function (xmlData) {
|
|
|
322
323
|
tagName = newTagName;
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
if (this.options.strictReservedNames &&
|
|
327
|
+
(tagName === this.options.commentPropName
|
|
328
|
+
|| tagName === this.options.cdataPropName
|
|
329
|
+
)) {
|
|
330
|
+
throw new Error(`Invalid tag name: ${tagName}`);
|
|
331
|
+
}
|
|
332
|
+
|
|
325
333
|
//save text as child node
|
|
326
334
|
if (currentNode && textData) {
|
|
327
335
|
if (currentNode.tagname !== '!xml') {
|
|
@@ -406,9 +414,23 @@ const parseXml = function (xmlData) {
|
|
|
406
414
|
this.addChild(currentNode, childNode, jPath, startIndex);
|
|
407
415
|
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
408
416
|
}
|
|
417
|
+
else if(this.options.unpairedTags.indexOf(tagName) !== -1){//unpaired tag
|
|
418
|
+
const childNode = new xmlNode(tagName);
|
|
419
|
+
if(tagName !== tagExp && attrExpPresent){
|
|
420
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
421
|
+
}
|
|
422
|
+
this.addChild(currentNode, childNode, jPath, startIndex);
|
|
423
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
424
|
+
i = result.closeIndex;
|
|
425
|
+
// Continue to next iteration without changing currentNode
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
409
428
|
//opening tag
|
|
410
429
|
else {
|
|
411
430
|
const childNode = new xmlNode(tagName);
|
|
431
|
+
if (this.tagsNodeStack.length > this.options.maxNestedTags) {
|
|
432
|
+
throw new Error("Maximum nested tags exceeded");
|
|
433
|
+
}
|
|
412
434
|
this.tagsNodeStack.push(currentNode);
|
|
413
435
|
|
|
414
436
|
if (tagName !== tagExp && attrExpPresent) {
|
|
@@ -524,19 +546,19 @@ const replaceEntitiesValue = function (val, tagName, jPath) {
|
|
|
524
546
|
}
|
|
525
547
|
|
|
526
548
|
|
|
527
|
-
function saveTextToParentTag(textData,
|
|
549
|
+
function saveTextToParentTag(textData, parentNode, jPath, isLeafNode) {
|
|
528
550
|
if (textData) { //store previously collected data as textNode
|
|
529
|
-
if (isLeafNode === undefined) isLeafNode =
|
|
551
|
+
if (isLeafNode === undefined) isLeafNode = parentNode.child.length === 0
|
|
530
552
|
|
|
531
553
|
textData = this.parseTextData(textData,
|
|
532
|
-
|
|
554
|
+
parentNode.tagname,
|
|
533
555
|
jPath,
|
|
534
556
|
false,
|
|
535
|
-
|
|
557
|
+
parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false,
|
|
536
558
|
isLeafNode);
|
|
537
559
|
|
|
538
560
|
if (textData !== undefined && textData !== "")
|
|
539
|
-
|
|
561
|
+
parentNode.add(this.options.textNodeName, textData);
|
|
540
562
|
textData = "";
|
|
541
563
|
}
|
|
542
564
|
return textData;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { buildOptions} from './OptionsBuilder.js';
|
|
1
|
+
import { buildOptions } from './OptionsBuilder.js';
|
|
2
2
|
import OrderedObjParser from './OrderedObjParser.js';
|
|
3
3
|
import prettify from './node2json.js';
|
|
4
|
-
import {validate} from "../validator.js";
|
|
4
|
+
import { validate } from "../validator.js";
|
|
5
5
|
import XmlNode from './xmlNode.js';
|
|
6
6
|
|
|
7
|
-
export default class XMLParser{
|
|
8
|
-
|
|
9
|
-
constructor(options){
|
|
7
|
+
export default class XMLParser {
|
|
8
|
+
|
|
9
|
+
constructor(options) {
|
|
10
10
|
this.externalEntities = {};
|
|
11
11
|
this.options = buildOptions(options);
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Parse XML dats to JS object
|
|
16
16
|
* @param {string|Uint8Array} xmlData
|
|
17
17
|
* @param {boolean|Object} validationOption
|
|
18
18
|
*/
|
|
19
|
-
parse(xmlData,validationOption){
|
|
20
|
-
if(typeof xmlData !== "string" && xmlData.toString){
|
|
19
|
+
parse(xmlData, validationOption) {
|
|
20
|
+
if (typeof xmlData !== "string" && xmlData.toString) {
|
|
21
21
|
xmlData = xmlData.toString();
|
|
22
|
-
}else if(typeof xmlData !== "string"){
|
|
22
|
+
} else if (typeof xmlData !== "string") {
|
|
23
23
|
throw new Error("XML data is accepted in String or Bytes[] form.")
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
if(
|
|
27
|
-
if(validationOption === true) validationOption = {}; //validate with default options
|
|
28
|
-
|
|
25
|
+
|
|
26
|
+
if (validationOption) {
|
|
27
|
+
if (validationOption === true) validationOption = {}; //validate with default options
|
|
28
|
+
|
|
29
29
|
const result = validate(xmlData, validationOption);
|
|
30
30
|
if (result !== true) {
|
|
31
|
-
|
|
31
|
+
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`)
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
}
|
|
34
34
|
const orderedObjParser = new OrderedObjParser(this.options);
|
|
35
35
|
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
36
36
|
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
37
|
-
if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;
|
|
37
|
+
if (this.options.preserveOrder || orderedResult === undefined) return orderedResult;
|
|
38
38
|
else return prettify(orderedResult, this.options);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -43,14 +43,14 @@ export default class XMLParser{
|
|
|
43
43
|
* @param {string} key
|
|
44
44
|
* @param {string} value
|
|
45
45
|
*/
|
|
46
|
-
addEntity(key, value){
|
|
47
|
-
if(value.indexOf("&") !== -1){
|
|
46
|
+
addEntity(key, value) {
|
|
47
|
+
if (value.indexOf("&") !== -1) {
|
|
48
48
|
throw new Error("Entity value can't have '&'")
|
|
49
|
-
}else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
|
|
49
|
+
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
50
50
|
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'")
|
|
51
|
-
}else if(value === "&"){
|
|
51
|
+
} else if (value === "&") {
|
|
52
52
|
throw new Error("An entity with value '&' is not permitted");
|
|
53
|
-
}else{
|
|
53
|
+
} else {
|
|
54
54
|
this.externalEntities[key] = value;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -10,8 +10,8 @@ const METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
|
|
|
10
10
|
* @param {any} options
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
export default function prettify(node, options){
|
|
14
|
-
return compress(
|
|
13
|
+
export default function prettify(node, options) {
|
|
14
|
+
return compress(node, options);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -21,78 +21,82 @@ export default function prettify(node, options){
|
|
|
21
21
|
* @param {string} jPath
|
|
22
22
|
* @returns object
|
|
23
23
|
*/
|
|
24
|
-
function compress(arr, options, jPath){
|
|
24
|
+
function compress(arr, options, jPath) {
|
|
25
25
|
let text;
|
|
26
|
-
const compressedObj = {};
|
|
26
|
+
const compressedObj = {}; //This is intended to be a plain object
|
|
27
27
|
for (let i = 0; i < arr.length; i++) {
|
|
28
28
|
const tagObj = arr[i];
|
|
29
29
|
const property = propName(tagObj);
|
|
30
30
|
let newJpath = "";
|
|
31
|
-
if(jPath === undefined) newJpath = property;
|
|
31
|
+
if (jPath === undefined) newJpath = property;
|
|
32
32
|
else newJpath = jPath + "." + property;
|
|
33
33
|
|
|
34
|
-
if(property === options.textNodeName){
|
|
35
|
-
if(text === undefined) text = tagObj[property];
|
|
34
|
+
if (property === options.textNodeName) {
|
|
35
|
+
if (text === undefined) text = tagObj[property];
|
|
36
36
|
else text += "" + tagObj[property];
|
|
37
|
-
}else if(property === undefined){
|
|
37
|
+
} else if (property === undefined) {
|
|
38
38
|
continue;
|
|
39
|
-
}else if(tagObj[property]){
|
|
40
|
-
|
|
39
|
+
} else if (tagObj[property]) {
|
|
40
|
+
|
|
41
41
|
let val = compress(tagObj[property], options, newJpath);
|
|
42
42
|
const isLeaf = isLeafTag(val, options);
|
|
43
|
-
if (tagObj[METADATA_SYMBOL] !== undefined) {
|
|
44
|
-
val[METADATA_SYMBOL] = tagObj[METADATA_SYMBOL]; // copy over metadata
|
|
45
|
-
}
|
|
46
43
|
|
|
47
|
-
if(tagObj[":@"]){
|
|
48
|
-
assignAttributes(
|
|
49
|
-
}else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){
|
|
44
|
+
if (tagObj[":@"]) {
|
|
45
|
+
assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
46
|
+
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode) {
|
|
50
47
|
val = val[options.textNodeName];
|
|
51
|
-
}else if(Object.keys(val).length === 0){
|
|
52
|
-
if(options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
48
|
+
} else if (Object.keys(val).length === 0) {
|
|
49
|
+
if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
53
50
|
else val = "";
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
if(
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if (tagObj[METADATA_SYMBOL] !== undefined && typeof val === "object" && val !== null) {
|
|
54
|
+
val[METADATA_SYMBOL] = tagObj[METADATA_SYMBOL]; // copy over metadata
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if (compressedObj[property] !== undefined && Object.prototype.hasOwnProperty.call(compressedObj, property)) {
|
|
59
|
+
if (!Array.isArray(compressedObj[property])) {
|
|
60
|
+
compressedObj[property] = [compressedObj[property]];
|
|
59
61
|
}
|
|
60
62
|
compressedObj[property].push(val);
|
|
61
|
-
}else{
|
|
63
|
+
} else {
|
|
62
64
|
//TODO: if a node is not an array, then check if it should be an array
|
|
63
65
|
//also determine if it is a leaf node
|
|
64
|
-
if (options.isArray(property, newJpath, isLeaf
|
|
66
|
+
if (options.isArray(property, newJpath, isLeaf)) {
|
|
65
67
|
compressedObj[property] = [val];
|
|
66
|
-
}else{
|
|
68
|
+
} else {
|
|
67
69
|
compressedObj[property] = val;
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
|
|
72
74
|
}
|
|
73
75
|
// if(text && text.length > 0) compressedObj[options.textNodeName] = text;
|
|
74
|
-
if(typeof text === "string"){
|
|
75
|
-
if(text.length > 0) compressedObj[options.textNodeName] = text;
|
|
76
|
-
}else if(text !== undefined) compressedObj[options.textNodeName] = text;
|
|
76
|
+
if (typeof text === "string") {
|
|
77
|
+
if (text.length > 0) compressedObj[options.textNodeName] = text;
|
|
78
|
+
} else if (text !== undefined) compressedObj[options.textNodeName] = text;
|
|
79
|
+
|
|
80
|
+
|
|
77
81
|
return compressedObj;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
function propName(obj){
|
|
84
|
+
function propName(obj) {
|
|
81
85
|
const keys = Object.keys(obj);
|
|
82
86
|
for (let i = 0; i < keys.length; i++) {
|
|
83
87
|
const key = keys[i];
|
|
84
|
-
if(key !== ":@") return key;
|
|
88
|
+
if (key !== ":@") return key;
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
function assignAttributes(obj, attrMap, jpath, options){
|
|
92
|
+
function assignAttributes(obj, attrMap, jpath, options) {
|
|
89
93
|
if (attrMap) {
|
|
90
94
|
const keys = Object.keys(attrMap);
|
|
91
95
|
const len = keys.length; //don't make it inline
|
|
92
96
|
for (let i = 0; i < len; i++) {
|
|
93
97
|
const atrrName = keys[i];
|
|
94
98
|
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
95
|
-
obj[atrrName] = [
|
|
99
|
+
obj[atrrName] = [attrMap[atrrName]];
|
|
96
100
|
} else {
|
|
97
101
|
obj[atrrName] = attrMap[atrrName];
|
|
98
102
|
}
|
|
@@ -100,10 +104,10 @@ function assignAttributes(obj, attrMap, jpath, options){
|
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
function isLeafTag(obj, options){
|
|
107
|
+
function isLeafTag(obj, options) {
|
|
104
108
|
const { textNodeName } = options;
|
|
105
109
|
const propCount = Object.keys(obj).length;
|
|
106
|
-
|
|
110
|
+
|
|
107
111
|
if (propCount === 0) {
|
|
108
112
|
return true;
|
|
109
113
|
}
|
|
@@ -8,23 +8,23 @@ if (typeof Symbol !== "function") {
|
|
|
8
8
|
METADATA_SYMBOL = Symbol("XML Node Metadata");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export default class XmlNode{
|
|
11
|
+
export default class XmlNode {
|
|
12
12
|
constructor(tagname) {
|
|
13
13
|
this.tagname = tagname;
|
|
14
14
|
this.child = []; //nested tags, text, cdata, comments in order
|
|
15
|
-
this[":@"] =
|
|
15
|
+
this[":@"] = Object.create(null); //attributes map
|
|
16
16
|
}
|
|
17
|
-
add(key,val){
|
|
17
|
+
add(key, val) {
|
|
18
18
|
// this.child.push( {name : key, val: val, isCdata: isCdata });
|
|
19
|
-
if(key === "__proto__") key = "#__proto__";
|
|
20
|
-
this.child.push(
|
|
19
|
+
if (key === "__proto__") key = "#__proto__";
|
|
20
|
+
this.child.push({ [key]: val });
|
|
21
21
|
}
|
|
22
22
|
addChild(node, startIndex) {
|
|
23
|
-
if(node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
24
|
-
if(node[":@"] && Object.keys(node[":@"]).length > 0){
|
|
25
|
-
this.child.push(
|
|
26
|
-
}else{
|
|
27
|
-
this.child.push(
|
|
23
|
+
if (node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
24
|
+
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
25
|
+
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
26
|
+
} else {
|
|
27
|
+
this.child.push({ [node.tagname]: node.child });
|
|
28
28
|
}
|
|
29
29
|
// if requested, add the startIndex
|
|
30
30
|
if (startIndex !== undefined) {
|