mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
Fix: Cast to string then eval
This commit is contained in:
parent
23f844d871
commit
82352910bf
2 changed files with 12 additions and 12 deletions
12
src/util.js
12
src/util.js
|
@ -413,24 +413,24 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue
|
||||||
case ">=":
|
case ">=":
|
||||||
case "<":
|
case "<":
|
||||||
case "<=":
|
case "<=":
|
||||||
jsonQueryExpression = `$.value ${jsonPathOperator} $.expected`;
|
jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`;
|
||||||
break;
|
break;
|
||||||
case "!=":
|
case "!=":
|
||||||
jsonQueryExpression = "$string($.value) != $string($.expected)";
|
jsonQueryExpression = "$.value != $.expected";
|
||||||
break;
|
break;
|
||||||
case "==":
|
case "==":
|
||||||
jsonQueryExpression = "$string($.value) = $string($.expected)";
|
jsonQueryExpression = "$.value = $.expected";
|
||||||
break;
|
break;
|
||||||
case "contains":
|
case "contains":
|
||||||
jsonQueryExpression = "$contains($string($.value), $string($.expected))";
|
jsonQueryExpression = "$contains($.value, $.expected)";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
||||||
}
|
}
|
||||||
const expression = jsonata(jsonQueryExpression);
|
const expression = jsonata(jsonQueryExpression);
|
||||||
const status = await expression.evaluate({
|
const status = await expression.evaluate({
|
||||||
value: response,
|
value: response.toString(),
|
||||||
expected: expectedValue
|
expected: expectedValue.toString()
|
||||||
});
|
});
|
||||||
if (response === undefined || status === undefined) {
|
if (response === undefined || status === undefined) {
|
||||||
throw new Error("Query evaluation returned undefined. Check query syntax and the structure of the response data");
|
throw new Error("Query evaluation returned undefined. Check query syntax and the structure of the response data");
|
||||||
|
|
12
src/util.ts
12
src/util.ts
|
@ -674,16 +674,16 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe
|
||||||
case ">=":
|
case ">=":
|
||||||
case "<":
|
case "<":
|
||||||
case "<=":
|
case "<=":
|
||||||
jsonQueryExpression = `$.value ${jsonPathOperator} $.expected`;
|
jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`;
|
||||||
break;
|
break;
|
||||||
case "!=":
|
case "!=":
|
||||||
jsonQueryExpression = "$string($.value) != $string($.expected)";
|
jsonQueryExpression = "$.value != $.expected";
|
||||||
break;
|
break;
|
||||||
case "==":
|
case "==":
|
||||||
jsonQueryExpression = "$string($.value) = $string($.expected)";
|
jsonQueryExpression = "$.value = $.expected";
|
||||||
break;
|
break;
|
||||||
case "contains":
|
case "contains":
|
||||||
jsonQueryExpression = "$contains($string($.value), $string($.expected))";
|
jsonQueryExpression = "$contains($.value, $.expected)";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
||||||
|
@ -692,8 +692,8 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe
|
||||||
// Evaluate the JSON Query Expression
|
// Evaluate the JSON Query Expression
|
||||||
const expression = jsonata(jsonQueryExpression);
|
const expression = jsonata(jsonQueryExpression);
|
||||||
const status = await expression.evaluate({
|
const status = await expression.evaluate({
|
||||||
value: response,
|
value: response.toString(),
|
||||||
expected: expectedValue
|
expected: expectedValue.toString()
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response === undefined || status === undefined) {
|
if (response === undefined || status === undefined) {
|
||||||
|
|
Loading…
Reference in a new issue