mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter): no-useless-escape: do not crash on backslash character (#6048)
Fixes https://github.com/oxc-project/oxc/issues/6046 Unlike other escape sequences such as `/\w/`, this is not actually parsed as a single character: `/\c/` so we incorrectly try to get the character before the backslash, which doesn't exist.
This commit is contained in:
parent
58d333a533
commit
c047d423b1
1 changed files with 4 additions and 1 deletions
|
|
@ -190,7 +190,8 @@ fn check_character(
|
|||
unicode_sets: bool,
|
||||
) -> Option<Span> {
|
||||
let char_text = character.span.source_text(ctx.source_text());
|
||||
let is_escaped = char_text.starts_with('\\');
|
||||
// The character is escaped if it has at least two characters and the first character is a backslash
|
||||
let is_escaped = char_text.starts_with('\\') && char_text.len() >= 2;
|
||||
if !is_escaped {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -573,6 +574,8 @@ fn test() {
|
|||
r"/[[\-]\-]/v", // { "ecmaVersion": 2024 },
|
||||
r"/[\^]/v", // { "ecmaVersion": 2024 }
|
||||
r"/[\s\-(]/", // https://github.com/oxc-project/oxc/issues/5227
|
||||
r"/\c/", // https://github.com/oxc-project/oxc/issues/6046
|
||||
r"/\\c/", // https://github.com/oxc-project/oxc/issues/6046
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
|
|||
Loading…
Reference in a new issue