Skip to content

Commit bba9f7c

Browse files
authored
Enforce eslint eqeqeq rule (#320)
1 parent 4bd9577 commit bba9f7c

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"no-duplicate-imports": "error",
1616
"no-use-before-define": "error",
1717
"curly": "error",
18-
"eqeqeq": ["warn", "smart"],
18+
"eqeqeq": ["error", "smart"],
1919
"no-var": "error",
2020
"prefer-const": "error"
2121
}

lib/c14n-canonicalization.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class C14nCanonicalization {
3131
nsCompare(a, b) {
3232
const attr1 = a.prefix;
3333
const attr2 = b.prefix;
34-
if (attr1 == attr2) {
34+
if (attr1 === attr2) {
3535
return 0;
3636
}
3737
return attr1.localeCompare(attr2);
@@ -97,14 +97,14 @@ class C14nCanonicalization {
9797

9898
//handle the namespaceof the node itself
9999
if (node.prefix) {
100-
if (prefixesInScope.indexOf(node.prefix) == -1) {
100+
if (prefixesInScope.indexOf(node.prefix) === -1) {
101101
nsListToRender.push({
102102
prefix: node.prefix,
103103
namespaceURI: node.namespaceURI || defaultNsForPrefix[node.prefix],
104104
});
105105
prefixesInScope.push(node.prefix);
106106
}
107-
} else if (defaultNs != currNs) {
107+
} else if (defaultNs !== currNs) {
108108
//new default ns
109109
newDefaultNs = node.namespaceURI;
110110
res.push(' xmlns="', newDefaultNs, '"');
@@ -126,9 +126,9 @@ class C14nCanonicalization {
126126
//the prefix is not defined already
127127
if (
128128
attr.prefix &&
129-
prefixesInScope.indexOf(attr.prefix) == -1 &&
130-
attr.prefix != "xmlns" &&
131-
attr.prefix != "xml"
129+
prefixesInScope.indexOf(attr.prefix) === -1 &&
130+
attr.prefix !== "xmlns" &&
131+
attr.prefix !== "xml"
132132
) {
133133
nsListToRender.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
134134
prefixesInScope.push(attr.prefix);

lib/exclusive-canonicalization.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ExclusiveCanonicalization {
4242
nsCompare(a, b) {
4343
const attr1 = a.prefix;
4444
const attr2 = b.prefix;
45-
if (attr1 == attr2) {
45+
if (attr1 === attr2) {
4646
return 0;
4747
}
4848
return attr1.localeCompare(attr2);
@@ -122,7 +122,7 @@ class ExclusiveCanonicalization {
122122
namespaceURI: node.namespaceURI || defaultNsForPrefix[node.prefix],
123123
});
124124
}
125-
} else if (defaultNs != currNs) {
125+
} else if (defaultNs !== currNs) {
126126
//new default ns
127127
newDefaultNs = node.namespaceURI;
128128
res.push(' xmlns="', newDefaultNs, '"');
@@ -149,8 +149,8 @@ class ExclusiveCanonicalization {
149149
if (
150150
attr.prefix &&
151151
!isPrefixInScope(prefixesInScope, attr.prefix, attr.namespaceURI) &&
152-
attr.prefix != "xmlns" &&
153-
attr.prefix != "xml"
152+
attr.prefix !== "xmlns" &&
153+
attr.prefix !== "xml"
154154
) {
155155
nsListToRender.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
156156
prefixesInScope.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
@@ -278,14 +278,14 @@ class ExclusiveCanonicalization {
278278
/**
279279
* If the inclusiveNamespacesPrefixList has not been explicitly provided then look it up in CanonicalizationMethod/InclusiveNamespaces
280280
*/
281-
if (inclusiveNamespacesPrefixList.length == 0) {
281+
if (inclusiveNamespacesPrefixList.length === 0) {
282282
const CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod");
283-
if (CanonicalizationMethod.length != 0) {
283+
if (CanonicalizationMethod.length !== 0) {
284284
const inclusiveNamespaces = utils.findChilds(
285285
CanonicalizationMethod[0],
286286
"InclusiveNamespaces"
287287
);
288-
if (inclusiveNamespaces.length != 0) {
288+
if (inclusiveNamespaces.length !== 0) {
289289
inclusiveNamespacesPrefixList = inclusiveNamespaces[0]
290290
.getAttribute("PrefixList")
291291
.split(" ");
@@ -304,7 +304,7 @@ class ExclusiveCanonicalization {
304304
prefixList.forEach(function (prefix) {
305305
if (ancestorNamespaces) {
306306
ancestorNamespaces.forEach(function (ancestorNamespace) {
307-
if (prefix == ancestorNamespace.prefix) {
307+
if (prefix === ancestorNamespace.prefix) {
308308
node.setAttributeNS(
309309
"http://www.w3.org/2000/xmlns/",
310310
"xmlns:" + prefix,

lib/signed-xml.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class SignedXml {
154154

155155
getCanonSignedInfoXml(doc) {
156156
const signedInfo = utils.findChilds(this.signatureNode, "SignedInfo");
157-
if (signedInfo.length == 0) {
157+
if (signedInfo.length === 0) {
158158
throw new Error("could not find SignedInfo element in the message");
159159
}
160160

@@ -256,12 +256,12 @@ class SignedXml {
256256

257257
const ref = this.references[r];
258258
let elemXpath;
259-
const uri = ref.uri[0] == "#" ? ref.uri.substring(1) : ref.uri;
259+
const uri = ref.uri[0] === "#" ? ref.uri.substring(1) : ref.uri;
260260
let elem = [];
261261

262-
if (uri == "") {
262+
if (uri === "") {
263263
elem = xpath.select("//*", doc);
264-
} else if (uri.indexOf("'") != -1) {
264+
} else if (uri.indexOf("'") !== -1) {
265265
// xpath injection
266266
throw new Error("Cannot validate a uri with quotes inside it");
267267
} else {
@@ -290,7 +290,7 @@ class SignedXml {
290290
ref.xpath = elemXpath;
291291
}
292292

293-
if (elem.length == 0) {
293+
if (elem.length === 0) {
294294
this.validationErrors.push(
295295
"invalid signature: the signature references an element with uri " +
296296
ref.uri +
@@ -333,7 +333,7 @@ class SignedXml {
333333
".//*[local-name(.)='CanonicalizationMethod']/@Algorithm",
334334
signatureNode
335335
);
336-
if (nodes.length == 0) {
336+
if (nodes.length === 0) {
337337
throw new Error("could not find CanonicalizationMethod/@Algorithm element");
338338
}
339339
this.canonicalizationAlgorithm = nodes[0].value;
@@ -348,7 +348,7 @@ class SignedXml {
348348
".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']",
349349
signatureNode
350350
);
351-
if (references.length == 0) {
351+
if (references.length === 0) {
352352
throw new Error("could not find any Reference elements");
353353
}
354354

@@ -373,7 +373,7 @@ class SignedXml {
373373
*/
374374
loadReference(ref) {
375375
let nodes = utils.findChilds(ref, "DigestMethod");
376-
if (nodes.length == 0) {
376+
if (nodes.length === 0) {
377377
throw new Error("could not find DigestMethod in reference " + ref.toString());
378378
}
379379
const digestAlgoNode = nodes[0];
@@ -385,10 +385,10 @@ class SignedXml {
385385
const digestAlgo = attr.value;
386386

387387
nodes = utils.findChilds(ref, "DigestValue");
388-
if (nodes.length == 0) {
388+
if (nodes.length === 0) {
389389
throw new Error("could not find DigestValue node in reference " + ref.toString());
390390
}
391-
if (nodes[0].childNodes.length == 0 || !nodes[0].firstChild.data) {
391+
if (nodes[0].childNodes.length === 0 || !nodes[0].firstChild.data) {
392392
throw new Error("could not find the value of DigestValue in " + nodes[0].toString());
393393
}
394394
const digestValue = nodes[0].firstChild.data;
@@ -397,7 +397,7 @@ class SignedXml {
397397
let trans;
398398
let inclusiveNamespacesPrefixList;
399399
nodes = utils.findChilds(ref, "Transforms");
400-
if (nodes.length != 0) {
400+
if (nodes.length !== 0) {
401401
const transformsNode = nodes[0];
402402
const transformsAll = utils.findChilds(transformsNode, "Transform");
403403
for (const t in transformsAll) {
@@ -608,7 +608,7 @@ class SignedXml {
608608

609609
this.signatureNode = signatureDoc;
610610
let signedInfoNode = utils.findChilds(this.signatureNode, "SignedInfo");
611-
if (signedInfoNode.length == 0) {
611+
if (signedInfoNode.length === 0) {
612612
const err3 = new Error("could not find SignedInfo element in the message");
613613
if (!callback) {
614614
throw err3;
@@ -684,7 +684,7 @@ class SignedXml {
684684
const ref = this.references[n];
685685
const nodes = xpath.selectWithResolver(ref.xpath, doc, this.namespaceResolver);
686686

687-
if (nodes.length == 0) {
687+
if (nodes.length === 0) {
688688
throw new Error(
689689
"the following xpath cannot be signed because it was not found: " + ref.xpath
690690
);
@@ -786,7 +786,7 @@ class SignedXml {
786786
ensureHasId(node) {
787787
let attr;
788788

789-
if (this.idMode == "wssecurity") {
789+
if (this.idMode === "wssecurity") {
790790
attr = utils.findAttr(
791791
node,
792792
"Id",
@@ -812,7 +812,7 @@ class SignedXml {
812812
//add the attribute
813813
const id = "_" + this.id++;
814814

815-
if (this.idMode == "wssecurity") {
815+
if (this.idMode === "wssecurity") {
816816
node.setAttributeNS(
817817
"http://www.w3.org/2000/xmlns/",
818818
"xmlns:wsu",

lib/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const xpath = require("xpath");
22

33
function attrEqualsExplicitly(attr, localName, namespace) {
4-
return attr.localName == localName && (attr.namespaceURI == namespace || !namespace);
4+
return attr.localName === localName && (attr.namespaceURI === namespace || !namespace);
55
}
66

77
function attrEqualsImplicitly(attr, localName, namespace, node) {
88
return (
9-
attr.localName == localName &&
10-
((!attr.namespaceURI && node.namespaceURI == namespace) || !namespace)
9+
attr.localName === localName &&
10+
((!attr.namespaceURI && node.namespaceURI === namespace) || !namespace)
1111
);
1212
}
1313

@@ -27,7 +27,7 @@ function findAttr(node, localName, namespace) {
2727

2828
function findFirst(doc, path) {
2929
const nodes = xpath.select(path, doc);
30-
if (nodes.length == 0) {
30+
if (nodes.length === 0) {
3131
throw "could not find xpath " + path;
3232
}
3333
return nodes[0];
@@ -38,7 +38,7 @@ function findChilds(node, localName, namespace) {
3838
const res = [];
3939
for (let i = 0; i < node.childNodes.length; i++) {
4040
const child = node.childNodes[i];
41-
if (child.localName == localName && (child.namespaceURI == namespace || !namespace)) {
41+
if (child.localName === localName && (child.namespaceURI === namespace || !namespace)) {
4242
res.push(child);
4343
}
4444
}

test/signature-unit-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("Signature unit tests", function () {
123123
const signedXml = sig.getOriginalXmlWithIds();
124124
const doc = new dom().parseFromString(signedXml);
125125

126-
const op = nsMode == "equal" ? "=" : "!=";
126+
const op = nsMode === "equal" ? "=" : "!=";
127127

128128
const xpath =
129129
"//*[local-name(.)='{elem}' and '_{id}' = @*[local-name(.)='Id' and namespace-uri(.)" +

0 commit comments

Comments
 (0)