Fix regex

This commit is contained in:
Yarmo Mackenbach 2020-10-26 22:50:41 +01:00
parent c49cc20953
commit f6738e978d

View file

@ -11,7 +11,7 @@ const runOnJson = (proofData, checkPath, checkClaim, checkRelation) => {
switch (checkRelation) { switch (checkRelation) {
default: default:
case 'contains': case 'contains':
re = new RegExp(checkClaim, "gi") re = new RegExp(checkClaim.replace('[', '\\[').replace(']', '\\]'), "gi")
return re.test(proofData.replace(/\r?\n|\r/, '')) return re.test(proofData.replace(/\r?\n|\r/, ''))
break break
case 'equals': case 'equals':
@ -27,7 +27,7 @@ const runOnJson = (proofData, checkPath, checkClaim, checkRelation) => {
if (Array.isArray(proofData)) { if (Array.isArray(proofData)) {
proofData.forEach((item, i) => { proofData.forEach((item, i) => {
isVerified = isVerified || runOnJson(item, checkPath, checkClaim, checkRelation) isVerified = isVerified || runOnJson(item, checkPath, checkClaim, checkRelation)
}); })
} else if (Array.isArray(proofData[checkPath[0]])) { } else if (Array.isArray(proofData[checkPath[0]])) {
proofData[checkPath[0]].forEach((item, i) => { proofData[checkPath[0]].forEach((item, i) => {
isVerified = isVerified || runOnJson(item, checkPath.slice(1), checkClaim, checkRelation) isVerified = isVerified || runOnJson(item, checkPath.slice(1), checkClaim, checkRelation)