Skip to content

Commit

Permalink
Enforce eslint eqeqeq rule
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Jun 23, 2023
1 parent 4bd9577 commit 3fa348d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"no-duplicate-imports": "error",
"no-use-before-define": "error",
"curly": "error",
"eqeqeq": ["warn", "smart"],
"eqeqeq": ["error", "smart"],
"no-var": "error",
"prefer-const": "error"
}
Expand Down
12 changes: 6 additions & 6 deletions lib/c14n-canonicalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class C14nCanonicalization {
nsCompare(a, b) {
const attr1 = a.prefix;
const attr2 = b.prefix;
if (attr1 == attr2) {
if (attr1 === attr2) {
return 0;
}
return attr1.localeCompare(attr2);
Expand Down Expand Up @@ -97,14 +97,14 @@ class C14nCanonicalization {

//handle the namespaceof the node itself
if (node.prefix) {
if (prefixesInScope.indexOf(node.prefix) == -1) {
if (prefixesInScope.indexOf(node.prefix) === -1) {
nsListToRender.push({
prefix: node.prefix,
namespaceURI: node.namespaceURI || defaultNsForPrefix[node.prefix],
});
prefixesInScope.push(node.prefix);
}
} else if (defaultNs != currNs) {
} else if (defaultNs !== currNs) {
//new default ns
newDefaultNs = node.namespaceURI;
res.push(' xmlns="', newDefaultNs, '"');
Expand All @@ -126,9 +126,9 @@ class C14nCanonicalization {
//the prefix is not defined already
if (
attr.prefix &&
prefixesInScope.indexOf(attr.prefix) == -1 &&
attr.prefix != "xmlns" &&
attr.prefix != "xml"
prefixesInScope.indexOf(attr.prefix) === -1 &&
attr.prefix !== "xmlns" &&
attr.prefix !== "xml"
) {
nsListToRender.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
prefixesInScope.push(attr.prefix);
Expand Down
16 changes: 8 additions & 8 deletions lib/exclusive-canonicalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExclusiveCanonicalization {
nsCompare(a, b) {
const attr1 = a.prefix;
const attr2 = b.prefix;
if (attr1 == attr2) {
if (attr1 === attr2) {
return 0;
}
return attr1.localeCompare(attr2);
Expand Down Expand Up @@ -122,7 +122,7 @@ class ExclusiveCanonicalization {
namespaceURI: node.namespaceURI || defaultNsForPrefix[node.prefix],
});
}
} else if (defaultNs != currNs) {
} else if (defaultNs !== currNs) {
//new default ns
newDefaultNs = node.namespaceURI;
res.push(' xmlns="', newDefaultNs, '"');
Expand All @@ -149,8 +149,8 @@ class ExclusiveCanonicalization {
if (
attr.prefix &&
!isPrefixInScope(prefixesInScope, attr.prefix, attr.namespaceURI) &&
attr.prefix != "xmlns" &&
attr.prefix != "xml"
attr.prefix !== "xmlns" &&
attr.prefix !== "xml"
) {
nsListToRender.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
prefixesInScope.push({ prefix: attr.prefix, namespaceURI: attr.namespaceURI });
Expand Down Expand Up @@ -278,14 +278,14 @@ class ExclusiveCanonicalization {
/**
* If the inclusiveNamespacesPrefixList has not been explicitly provided then look it up in CanonicalizationMethod/InclusiveNamespaces
*/
if (inclusiveNamespacesPrefixList.length == 0) {
if (inclusiveNamespacesPrefixList.length === 0) {
const CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod");
if (CanonicalizationMethod.length != 0) {
if (CanonicalizationMethod.length !== 0) {
const inclusiveNamespaces = utils.findChilds(
CanonicalizationMethod[0],
"InclusiveNamespaces"
);
if (inclusiveNamespaces.length != 0) {
if (inclusiveNamespaces.length !== 0) {
inclusiveNamespacesPrefixList = inclusiveNamespaces[0]
.getAttribute("PrefixList")
.split(" ");
Expand All @@ -304,7 +304,7 @@ class ExclusiveCanonicalization {
prefixList.forEach(function (prefix) {
if (ancestorNamespaces) {
ancestorNamespaces.forEach(function (ancestorNamespace) {
if (prefix == ancestorNamespace.prefix) {
if (prefix === ancestorNamespace.prefix) {
node.setAttributeNS(
"http://www.w3.org/2000/xmlns/",
"xmlns:" + prefix,
Expand Down
30 changes: 15 additions & 15 deletions lib/signed-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SignedXml {

getCanonSignedInfoXml(doc) {
const signedInfo = utils.findChilds(this.signatureNode, "SignedInfo");
if (signedInfo.length == 0) {
if (signedInfo.length === 0) {
throw new Error("could not find SignedInfo element in the message");
}

Expand Down Expand Up @@ -256,12 +256,12 @@ class SignedXml {

const ref = this.references[r];
let elemXpath;
const uri = ref.uri[0] == "#" ? ref.uri.substring(1) : ref.uri;
const uri = ref.uri[0] === "#" ? ref.uri.substring(1) : ref.uri;
let elem = [];

if (uri == "") {
if (uri === "") {
elem = xpath.select("//*", doc);
} else if (uri.indexOf("'") != -1) {
} else if (uri.indexOf("'") !== -1) {
// xpath injection
throw new Error("Cannot validate a uri with quotes inside it");
} else {
Expand Down Expand Up @@ -290,7 +290,7 @@ class SignedXml {
ref.xpath = elemXpath;
}

if (elem.length == 0) {
if (elem.length === 0) {
this.validationErrors.push(
"invalid signature: the signature references an element with uri " +
ref.uri +
Expand Down Expand Up @@ -333,7 +333,7 @@ class SignedXml {
".//*[local-name(.)='CanonicalizationMethod']/@Algorithm",
signatureNode
);
if (nodes.length == 0) {
if (nodes.length === 0) {
throw new Error("could not find CanonicalizationMethod/@Algorithm element");
}
this.canonicalizationAlgorithm = nodes[0].value;
Expand All @@ -348,7 +348,7 @@ class SignedXml {
".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']",
signatureNode
);
if (references.length == 0) {
if (references.length === 0) {
throw new Error("could not find any Reference elements");
}

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

nodes = utils.findChilds(ref, "DigestValue");
if (nodes.length == 0) {
if (nodes.length === 0) {
throw new Error("could not find DigestValue node in reference " + ref.toString());
}
if (nodes[0].childNodes.length == 0 || !nodes[0].firstChild.data) {
if (nodes[0].childNodes.length === 0 || !nodes[0].firstChild.data) {
throw new Error("could not find the value of DigestValue in " + nodes[0].toString());
}
const digestValue = nodes[0].firstChild.data;
Expand All @@ -397,7 +397,7 @@ class SignedXml {
let trans;
let inclusiveNamespacesPrefixList;
nodes = utils.findChilds(ref, "Transforms");
if (nodes.length != 0) {
if (nodes.length !== 0) {
const transformsNode = nodes[0];
const transformsAll = utils.findChilds(transformsNode, "Transform");
for (const t in transformsAll) {
Expand Down Expand Up @@ -608,7 +608,7 @@ class SignedXml {

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

if (nodes.length == 0) {
if (nodes.length === 0) {
throw new Error(
"the following xpath cannot be signed because it was not found: " + ref.xpath
);
Expand Down Expand Up @@ -786,7 +786,7 @@ class SignedXml {
ensureHasId(node) {
let attr;

if (this.idMode == "wssecurity") {
if (this.idMode === "wssecurity") {
attr = utils.findAttr(
node,
"Id",
Expand All @@ -812,7 +812,7 @@ class SignedXml {
//add the attribute
const id = "_" + this.id++;

if (this.idMode == "wssecurity") {
if (this.idMode === "wssecurity") {
node.setAttributeNS(
"http://www.w3.org/2000/xmlns/",
"xmlns:wsu",
Expand Down
10 changes: 5 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const xpath = require("xpath");

function attrEqualsExplicitly(attr, localName, namespace) {
return attr.localName == localName && (attr.namespaceURI == namespace || !namespace);
return attr.localName === localName && (attr.namespaceURI === namespace || !namespace);
}

function attrEqualsImplicitly(attr, localName, namespace, node) {
return (
attr.localName == localName &&
((!attr.namespaceURI && node.namespaceURI == namespace) || !namespace)
attr.localName === localName &&
((!attr.namespaceURI && node.namespaceURI === namespace) || !namespace)
);
}

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

function findFirst(doc, path) {
const nodes = xpath.select(path, doc);
if (nodes.length == 0) {
if (nodes.length === 0) {
throw "could not find xpath " + path;
}
return nodes[0];
Expand All @@ -38,7 +38,7 @@ function findChilds(node, localName, namespace) {
const res = [];
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes[i];
if (child.localName == localName && (child.namespaceURI == namespace || !namespace)) {
if (child.localName === localName && (child.namespaceURI === namespace || !namespace)) {
res.push(child);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/signature-unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("Signature unit tests", function () {
const signedXml = sig.getOriginalXmlWithIds();
const doc = new dom().parseFromString(signedXml);

const op = nsMode == "equal" ? "=" : "!=";
const op = nsMode === "equal" ? "=" : "!=";

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

0 comments on commit 3fa348d

Please sign in to comment.