From 83d119ab03ae75ee15d7fcb15006710ea7ede50f Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 11 Nov 2024 14:53:17 +0000 Subject: [PATCH] Fix non-strict whitespace matching newlines (fixes #37) (#38) This fixes a bug where `x x` would be translated to `x\s+x`, which is subtly wrong as `\s` allows newline matching. The more correct way is `x[ \t\v]+x`, which it now is with this patch. Fixes #37 --- filecheck/compiler.py | 4 +++- tests/filecheck/issue-37.test | 9 +++++++++ tests/filecheck/regex.test | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/filecheck/issue-37.test diff --git a/filecheck/compiler.py b/filecheck/compiler.py index bf39087..0d82948 100644 --- a/filecheck/compiler.py +++ b/filecheck/compiler.py @@ -39,7 +39,9 @@ def compile_uops( # but I still want to regex escape them # and re.sub doesn't let me insert \s into the new string for some reason...... expr.append( - re.sub(r"(\\ )+", " ", re.escape(uop.content)).replace(" ", r"\s+") + re.sub(r"(\\ )+", " ", re.escape(uop.content)).replace( + " ", r"[ \t\v]+" + ), ) elif isinstance(uop, RE): diff --git a/tests/filecheck/issue-37.test b/tests/filecheck/issue-37.test new file mode 100644 index 0000000..9c15df8 --- /dev/null +++ b/tests/filecheck/issue-37.test @@ -0,0 +1,9 @@ +// RUN: strip-comments.sh %s | filecheck %s + +ax +x, x, +x, + +// CHECK: ax +// CHECK-NEXT: x, x, +// CHECK: x, diff --git a/tests/filecheck/regex.test b/tests/filecheck/regex.test index cd648e8..ea6d524 100644 --- a/tests/filecheck/regex.test +++ b/tests/filecheck/regex.test @@ -15,7 +15,7 @@ test 123, 123 test a b // CHECK: test {{a|b}} {{b|c}} -test something +test something // CHECK: test something {{$}} test another thing