Skip to content

Commit

Permalink
fix(linter) fix panic in no hex escape
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Nov 24, 2023
1 parent 32b1956 commit 3044e21
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare_oxc_lint!(
fn check_escape(value: &str) -> Option<String> {
let mut in_escape = false;
let mut matched = Vec::new();
for (index, c) in value.chars().enumerate() {
for (index, c) in value.char_indices() {
if c == '\\' && !in_escape {
in_escape = true;
} else if c == 'x' && in_escape {
Expand All @@ -68,6 +68,7 @@ fn check_escape(value: &str) -> Option<String> {
Some(fixed)
}
}

impl Rule for NoHexEscape {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
match node.kind() {
Expand Down Expand Up @@ -137,7 +138,12 @@ fn test() {
r"const foo = `\\\\xd8\\\\x3d\\\\xdc\\\\xa9`",
r"const foo = `foo\\\\x12foo\\\\x34`",
];
let fail = vec![r#"const foo = "\xb1""#];

let fail = vec![
r#"const foo = "\xb1""#,
r"wrapId(/(^|[<nonId>])(?:алг|арг(?:\x20*рез)?|ввод|ВКЛЮЧИТЬ|вс[её]|выбор|вывод|выход|дано|для|до|дс|если|иначе|исп|использовать|кон(?:(?:\x20+|_)исп)?|кц(?:(?:\x20+|_)при)?|надо|нач|нс|нц|от|пауза|пока|при|раза?|рез|стоп|таб|то|утв|шаг)(?=[<nonId>]|$)/.source)",
];

let fix = vec![
(r"const foo = '\xb1'", r"const foo = '\u00b1'", None),
(r"const foo = '\\\xb1'", r"const foo = '\\\u00b1'", None),
Expand Down

0 comments on commit 3044e21

Please sign in to comment.