Skip to content

Commit b3e5ecd

Browse files
committed
Enforce eslint no-prototype-builtins
1 parent bba9f7c commit b3e5ecd

File tree

5 files changed

+33
-109
lines changed

5 files changed

+33
-109
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"rules": {
1111
"no-console": "error",
1212
"no-unused-vars": "warn",
13-
"no-prototype-builtins": "warn",
13+
"no-prototype-builtins": "error",
1414
"one-var": ["error", "never"],
1515
"no-duplicate-imports": "error",
1616
"no-use-before-define": "error",

lib/c14n-canonicalization.js

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ class C14nCanonicalization {
3838
}
3939

4040
renderAttrs(node, defaultNS) {
41-
let a;
4241
let i;
4342
let attr;
44-
const res = [];
4543
const attrListToRender = [];
4644

4745
if (node.nodeType === 8) {
@@ -61,14 +59,9 @@ class C14nCanonicalization {
6159

6260
attrListToRender.sort(this.attrCompare);
6361

64-
for (a in attrListToRender) {
65-
if (!attrListToRender.hasOwnProperty(a)) {
66-
continue;
67-
}
68-
69-
attr = attrListToRender[a];
70-
res.push(" ", attr.name, '="', utils.encodeSpecialCharactersInAttribute(attr.value), '"');
71-
}
62+
const res = attrListToRender.map((attr) => {
63+
return ` ${attr.name}="${utils.encodeSpecialCharactersInAttribute(attr.value)}"`;
64+
});
7265

7366
return res.join("");
7467
}
@@ -86,16 +79,14 @@ class C14nCanonicalization {
8679
* @api private
8780
*/
8881
renderNs(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces) {
89-
let a;
9082
let i;
91-
let p;
9283
let attr;
9384
const res = [];
9485
let newDefaultNs = defaultNs;
9586
const nsListToRender = [];
9687
const currNs = node.namespaceURI || "";
9788

98-
//handle the namespaceof the node itself
89+
//handle the namespace of the node itself
9990
if (node.prefix) {
10091
if (prefixesInScope.indexOf(node.prefix) === -1) {
10192
nsListToRender.push({
@@ -138,37 +129,27 @@ class C14nCanonicalization {
138129

139130
if (Array.isArray(ancestorNamespaces) && ancestorNamespaces.length > 0) {
140131
// Remove namespaces which are already present in nsListToRender
141-
for (const p1 in ancestorNamespaces) {
142-
if (!ancestorNamespaces.hasOwnProperty(p1)) {
143-
continue;
144-
}
132+
for (const ancestorNamespace of ancestorNamespaces) {
145133
let alreadyListed = false;
146-
for (const p2 in nsListToRender) {
134+
for (const nsToRender of nsListToRender) {
147135
if (
148-
nsListToRender[p2].prefix === ancestorNamespaces[p1].prefix &&
149-
nsListToRender[p2].namespaceURI === ancestorNamespaces[p1].namespaceURI
136+
nsToRender.prefix === ancestorNamespace.prefix &&
137+
nsToRender.namespaceURI === ancestorNamespace.namespaceURI
150138
) {
151139
alreadyListed = true;
152140
}
153141
}
154142

155143
if (!alreadyListed) {
156-
nsListToRender.push(ancestorNamespaces[p1]);
144+
nsListToRender.push(ancestorNamespace);
157145
}
158146
}
159147
}
160148

161149
nsListToRender.sort(this.nsCompare);
162150

163151
//render namespaces
164-
for (a in nsListToRender) {
165-
if (!nsListToRender.hasOwnProperty(a)) {
166-
continue;
167-
}
168-
169-
p = nsListToRender[a];
170-
res.push(" xmlns:", p.prefix, '="', p.namespaceURI, '"');
171-
}
152+
res.push(...nsListToRender.map((attr) => ` xmlns:${attr.prefix}="${attr.namespaceURI}"`));
172153

173154
return { rendered: res.join(""), newDefaultNs: newDefaultNs };
174155
}

lib/enveloped-signature.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ class EnvelopedSignature {
2525
".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",
2626
node
2727
);
28-
for (const h in signatures) {
29-
if (!signatures.hasOwnProperty(h)) {
30-
continue;
31-
}
32-
const nodeSignature = signatures[h];
28+
for (const nodeSignature of signatures) {
3329
const signatureValue = utils.findFirst(
3430
nodeSignature,
3531
".//*[local-name(.)='SignatureValue']/text()"

lib/exclusive-canonicalization.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class ExclusiveCanonicalization {
4949
}
5050

5151
renderAttrs(node, defaultNS) {
52-
let a;
5352
let i;
5453
let attr;
5554
const res = [];
@@ -72,12 +71,7 @@ class ExclusiveCanonicalization {
7271

7372
attrListToRender.sort(this.attrCompare);
7473

75-
for (a in attrListToRender) {
76-
if (!attrListToRender.hasOwnProperty(a)) {
77-
continue;
78-
}
79-
80-
attr = attrListToRender[a];
74+
for (attr of attrListToRender) {
8175
res.push(" ", attr.name, '="', utils.encodeSpecialCharactersInAttribute(attr.value), '"');
8276
}
8377

@@ -95,9 +89,7 @@ class ExclusiveCanonicalization {
9589
* @api private
9690
*/
9791
renderNs(node, prefixesInScope, defaultNs, defaultNsForPrefix, inclusiveNamespacesPrefixList) {
98-
let a;
9992
let i;
100-
let p;
10193
let attr;
10294
const res = [];
10395
let newDefaultNs = defaultNs;
@@ -161,12 +153,7 @@ class ExclusiveCanonicalization {
161153
nsListToRender.sort(this.nsCompare);
162154

163155
//render namespaces
164-
for (a in nsListToRender) {
165-
if (!nsListToRender.hasOwnProperty(a)) {
166-
continue;
167-
}
168-
169-
p = nsListToRender[a];
156+
for (const p of nsListToRender) {
170157
res.push(" xmlns:", p.prefix, '="', p.namespaceURI, '"');
171158
}
172159

lib/signed-xml.js

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,7 @@ class SignedXml {
249249
}
250250

251251
validateReferences(doc) {
252-
for (const r in this.references) {
253-
if (!this.references.hasOwnProperty(r)) {
254-
continue;
255-
}
256-
257-
const ref = this.references[r];
252+
for (const ref of this.references) {
258253
let elemXpath;
259254
const uri = ref.uri[0] === "#" ? ref.uri.substring(1) : ref.uri;
260255
let elem = [];
@@ -266,12 +261,8 @@ class SignedXml {
266261
throw new Error("Cannot validate a uri with quotes inside it");
267262
} else {
268263
let num_elements_for_id = 0;
269-
for (const index in this.idAttributes) {
270-
if (!this.idAttributes.hasOwnProperty(index)) {
271-
continue;
272-
}
273-
const tmp_elemXpath =
274-
"//*[@*[local-name(.)='" + this.idAttributes[index] + "']='" + uri + "']";
264+
for (const attr of this.idAttributes) {
265+
const tmp_elemXpath = `//*[@*[local-name(.)='${attr}']='${uri}']`;
275266
const tmp_elem = xpath.select(tmp_elemXpath, doc);
276267
num_elements_for_id += tmp_elem.length;
277268
if (tmp_elem.length > 0) {
@@ -352,12 +343,8 @@ class SignedXml {
352343
throw new Error("could not find any Reference elements");
353344
}
354345

355-
for (const i in references) {
356-
if (!references.hasOwnProperty(i)) {
357-
continue;
358-
}
359-
360-
this.loadReference(references[i]);
346+
for (const reference of references) {
347+
this.loadReference(reference);
361348
}
362349

363350
this.signatureValue = utils
@@ -400,15 +387,12 @@ class SignedXml {
400387
if (nodes.length !== 0) {
401388
const transformsNode = nodes[0];
402389
const transformsAll = utils.findChilds(transformsNode, "Transform");
403-
for (const t in transformsAll) {
404-
if (!transformsAll.hasOwnProperty(t)) {
405-
continue;
406-
}
407-
408-
trans = transformsAll[t];
390+
for (const t of transformsAll) {
391+
trans = t;
409392
transforms.push(utils.findAttr(trans, "Algorithm").value);
410393
}
411394

395+
// This is a little strange, we are looking for children of the last child of `transformsNode`
412396
const inclusiveNamespaces = utils.findChilds(trans, "InclusiveNamespaces");
413397
if (inclusiveNamespaces.length > 0) {
414398
//Should really only be one prefix list, but maybe there's some circumstances where more than one to lets handle it
@@ -676,12 +660,7 @@ class SignedXml {
676660
prefix = prefix || "";
677661
prefix = prefix ? prefix + ":" : prefix;
678662

679-
for (const n in this.references) {
680-
if (!this.references.hasOwnProperty(n)) {
681-
continue;
682-
}
683-
684-
const ref = this.references[n];
663+
for (const ref of this.references) {
685664
const nodes = xpath.selectWithResolver(ref.xpath, doc, this.namespaceResolver);
686665

687666
if (nodes.length === 0) {
@@ -690,12 +669,7 @@ class SignedXml {
690669
);
691670
}
692671

693-
for (const h in nodes) {
694-
if (!nodes.hasOwnProperty(h)) {
695-
continue;
696-
}
697-
698-
const node = nodes[h];
672+
for (const node of nodes) {
699673
if (ref.isEmptyUri) {
700674
res += "<" + prefix + 'Reference URI="">';
701675
} else {
@@ -704,12 +678,7 @@ class SignedXml {
704678
res += "<" + prefix + 'Reference URI="#' + id + '">';
705679
}
706680
res += "<" + prefix + "Transforms>";
707-
for (const t in ref.transforms) {
708-
if (!ref.transforms.hasOwnProperty(t)) {
709-
continue;
710-
}
711-
712-
const trans = ref.transforms[t];
681+
for (const trans of ref.transforms) {
713682
const transform = this.findCanonicalizationAlgorithm(trans);
714683
res += "<" + prefix + 'Transform Algorithm="' + transform.getAlgorithmName() + '"';
715684
if (ref.inclusiveNamespacesPrefixList) {
@@ -761,12 +730,8 @@ class SignedXml {
761730

762731
let canonXml = node.cloneNode(true); // Deep clone
763732

764-
for (const t in transforms) {
765-
if (!transforms.hasOwnProperty(t)) {
766-
continue;
767-
}
768-
769-
const transform = this.findCanonicalizationAlgorithm(transforms[t]);
733+
Object.values(transforms).forEach((transformName) => {
734+
const transform = this.findCanonicalizationAlgorithm(transformName);
770735
canonXml = transform.process(canonXml, options);
771736
//TODO: currently transform.process may return either Node or String value (enveloped transformation returns Node, exclusive-canonicalization returns String).
772737
//This either needs to be more explicit in the API, or all should return the same.
@@ -775,7 +740,8 @@ class SignedXml {
775740
//enveloped transformation returns Node since if it would return String consider this case:
776741
//<x xmlns:p='ns'><p:y/></x>
777742
//if only y is the node to sign then a string would be <p:y/> without the definition of the p namespace. probably xmldom toString() should have added it.
778-
}
743+
});
744+
779745
return canonXml.toString();
780746
}
781747

@@ -793,16 +759,10 @@ class SignedXml {
793759
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
794760
);
795761
} else {
796-
for (const index in this.idAttributes) {
797-
if (!this.idAttributes.hasOwnProperty(index)) {
798-
continue;
799-
}
800-
801-
attr = utils.findAttr(node, this.idAttributes[index], null);
802-
if (attr) {
803-
break;
804-
}
805-
}
762+
Object.values(this.idAttributes).some((idAttribute) => {
763+
attr = utils.findAttr(node, idAttribute, null);
764+
return !!attr; // This will break the loop as soon as a truthy attr is found.
765+
});
806766
}
807767

808768
if (attr) {

0 commit comments

Comments
 (0)