Skip to content

Commit

Permalink
Fix non-strict whitespace matching newlines (fixes #37) (#38)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AntonLydike authored Nov 11, 2024
1 parent 470b9e6 commit 83d119a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion filecheck/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions tests/filecheck/issue-37.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: strip-comments.sh %s | filecheck %s

ax
x, x,
x,

// CHECK: ax
// CHECK-NEXT: x, x,
// CHECK: x,
2 changes: 1 addition & 1 deletion tests/filecheck/regex.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83d119a

Please sign in to comment.