Skip to content

Commit

Permalink
syntax: \p{Sc} should map to \p{Currency_Symbol}
Browse files Browse the repository at this point in the history
'sc' refers to the 'Currency_Symbol' general category, but is also
the abbreviation for the 'Script' property. So when going through the
canonicalization process, it would get normalized to 'Script' before
being checked as a general category. We fix it by special casing it.

See also #719

Fixes #835, #899
  • Loading branch information
snsmac authored and BurntSushi committed Apr 17, 2023
1 parent 059f4d7 commit 9e6b094
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion regex-syntax/src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ impl<'a> ClassQuery<'a> {
// a general category. (Currently, we don't even support the
// 'Case_Folding' property. But if we do in the future, users will be
// required to spell it out.)
if norm != "cf" {
//
// Also 'sc' refers to the 'Currency_Symbol' general category, but is
// also the abbreviation for the 'Script' property. So we avoid calling
// 'canonical_prop' for it too, which would erroneously normalize it
// to 'Script'.
if norm != "cf" && norm != "sc" {
if let Some(canon) = canonical_prop(&norm)? {
return Ok(CanonicalClassQuery::Binary(canon));
}
Expand Down
1 change: 1 addition & 0 deletions tests/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mat!(uni_class_gencat_format, r"\p{Format}", "\u{E007F}", Some((0, 4)));
// See: https://github.com/rust-lang/regex/issues/719
mat!(uni_class_gencat_format_abbrev1, r"\p{cf}", "\u{E007F}", Some((0, 4)));
mat!(uni_class_gencat_format_abbrev2, r"\p{gc=cf}", "\u{E007F}", Some((0, 4)));
mat!(uni_class_gencat_format_abbrev3, r"\p{Sc}", "$", Some((0, 1)));
mat!(
uni_class_gencat_initial_punctuation,
r"\p{Initial_Punctuation}",
Expand Down

0 comments on commit 9e6b094

Please sign in to comment.