From 66a16d21a99a4e2b76ee5e71affbc8d528e505f5 Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Tue, 7 Jan 2020 10:19:09 +0000 Subject: [PATCH] JS: Fix buggy test cases --- .../RegExpAlwaysMatches/RegExpAlwaysMatches.expected | 2 ++ .../test/query-tests/RegExp/RegExpAlwaysMatches/tst.js | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/RegExpAlwaysMatches.expected b/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/RegExpAlwaysMatches.expected index 2cf07d65328..20c613bdd91 100644 --- a/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/RegExpAlwaysMatches.expected +++ b/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/RegExpAlwaysMatches.expected @@ -3,4 +3,6 @@ | tst.js:22:11:22:34 | ^(?:https?:\|ftp:\|file:)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:22:10:22:43 | /^(?:ht ... test(x) | here | | tst.js:30:11:30:20 | (foo\|bar)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:30:10:30:29 | /(foo\|bar)?/.test(x) | here | | tst.js:34:21:34:26 | (baz)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:34:10:34:35 | /^foo\|b ... test(x) | here | +| tst.js:58:20:58:25 | [a-z]* | This regular expression always the matches at index 0 when used $@, as it matches the empty substring. | tst.js:58:10:58:27 | x.search(/[a-z]*/) | here | +| tst.js:70:20:70:26 | ^(foo)? | This regular expression always the matches at index 0 when used $@, as it matches the empty substring. | tst.js:70:10:70:28 | x.search(/^(foo)?/) | here | | tst.js:86:22:86:21 | | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:86:10:86:31 | new Reg ... test(x) | here | diff --git a/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/tst.js b/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/tst.js index fad038ca799..1517393ad6e 100644 --- a/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/tst.js +++ b/javascript/ql/test/query-tests/RegExp/RegExpAlwaysMatches/tst.js @@ -55,23 +55,23 @@ function emptyAlt3(x) { } function search(x) { - return /[a-z]*/.search(x); // NOT OK + return x.search(/[a-z]*/); // NOT OK } function search2(x) { - return /[a-z]/.search(x); // OK + return x.search(/[a-z]/); // OK } function lookahead(x) { - return /(?!x)/.search(x); // OK + return x.search(/(?!x)/); // OK } function searchPrefix(x) { - return /^foo?/.search(x); // NOT OK - `foo?` does not affect the returned index + return x.search(/^(foo)?/); // NOT OK - `foo?` does not affect the returned index } function searchSuffix(x) { - return /foo?$/.search(x); // OK - `foo?` affects the returned index + return x.search(/(foo)?$/); // OK - `foo?` affects the returned index } function wordBoundary(x) {