Skip to content

Ensure [[:blank:]] only matches [ \t] #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regex-syntax/src/hir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ fn ascii_class(kind: &ast::ClassAsciiKind) -> &'static [(char, char)] {
X
}
Blank => {
const X: T = &[(' ', '\t')];
const X: T = &[('\t', '\t'), (' ', ' ')];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. Thanks for catching this! It looks like a bad transcription error. However, I don't think this is right either. The docs include more characters:

[[:space:]]    whitespace ([\t\n\v\f\r ])

And this is consistent with how regex-syntax 0.4 and below behaved:

const SPACE: Class = &[('\t', '\t'), ('\n', '\n'), ('\x0B', '\x0B'),
('\x0C', '\x0C'), ('\r', '\r'), (' ', ' ')];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BurntSushi You're referring to docs for space, but this bug and fix are for blank which has fewer characters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ug. Thanks for that. I don't think I had quite woken up yet!

X
}
Cntrl => {
Expand Down
17 changes: 17 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,20 @@ ismatch!(
r"typename type\-parameter\-\d+\-\d+::.+",
"test",
false);

// See: https://github.com/rust-lang/regex/issues/533
ismatch!(
blank_matches_nothing_between_space_and_tab,
r"[[:blank:]]",
"\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
\u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
false);

ismatch!(
inverted_blank_matches_everything_between_space_and_tab,
r"^[[:^blank:]]+$",
"\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
\u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
true);