Skip to content

Commit

Permalink
fix(regex): panic on displaying surrogated UnicodeEscape characters. (
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Sep 5, 2024
1 parent 0df1d9d commit 9b984b3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/oxc_regular_expression/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ fn character_to_string(
) -> (/* result */ String, /* true of peek should be consumed */ bool) {
let cp = this.value;

if let CharacterKind::Symbol = this.kind {
if matches!(this.kind, CharacterKind::Symbol | CharacterKind::UnicodeEscape) {
// Trail only
if is_trail_surrogate(cp) {
return (format!(r"\u{cp:X}"), false);
Expand Down Expand Up @@ -493,7 +493,7 @@ mod test {
(r"/\d/g", None),
// we lose the flags ordering
(r"/\d/ug", Some(r"/\d/gu")),
// NOTE: we capitalize hex unicodes.
// we capitalize hex unicodes.
(r"/\n\cM\0\x41\u{1f600}\./u", Some(r"/\n\cM\0\x41\u{1F600}\./u")),
(r"/c]/", None),
// Octal tests from: <https://github.com/tc39/test262/blob/d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60/test/annexB/language/literals/regexp/legacy-octal-escape.js>
Expand Down Expand Up @@ -540,6 +540,14 @@ mod test {
(r"/[\c8]/", None),
(r"/[\c80]+/", None),
(r"/\c_/", None),
// we capitalize hex unicodes.
(r"/^|\udf06/gu", Some(r"/^|\uDF06/gu")),
// we capitalize hex unicodes.
(r"/\udf06/", Some(r"/\uDF06/")),
// we capitalize hex unicodes.
(r"/\udf06/u", Some(r"/\uDF06/u")),
// we capitalize hex unicodes.
(r"/^|\udf06/g", Some(r"/^|\uDF06/g")),
];

fn test_display(allocator: &Allocator, (source, expect): &Case) {
Expand Down

0 comments on commit 9b984b3

Please sign in to comment.