Skip to content

Commit 5241919

Browse files
kennytmBurntSushi
authored andcommitted
syntax: fix [[:blank:]] character class
Ensure `[[:blank:]]` only matches `[ \t]`. It appears that there was a transcription error when `regex-syntax` was rewritten such that `[[:blank:]]` ended up matching more than it was supposed to. Fixes #533
1 parent 488fe56 commit 5241919

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

regex-syntax/src/hir/translate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ fn ascii_class(kind: &ast::ClassAsciiKind) -> &'static [(char, char)] {
10401040
X
10411041
}
10421042
Blank => {
1043-
const X: T = &[(' ', '\t')];
1043+
const X: T = &[('\t', '\t'), (' ', ' ')];
10441044
X
10451045
}
10461046
Cntrl => {

tests/regression.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,20 @@ ismatch!(
9292
r"typename type\-parameter\-\d+\-\d+::.+",
9393
"test",
9494
false);
95+
96+
// See: https://github.com/rust-lang/regex/issues/533
97+
ismatch!(
98+
blank_matches_nothing_between_space_and_tab,
99+
r"[[:blank:]]",
100+
"\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
101+
\u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
102+
\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
103+
false);
104+
105+
ismatch!(
106+
inverted_blank_matches_everything_between_space_and_tab,
107+
r"^[[:^blank:]]+$",
108+
"\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
109+
\u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
110+
\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
111+
true);

0 commit comments

Comments
 (0)