Skip to content
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

bug(linter): some text in js file cause panic (byte index 8 is not a char boundary) #1671

Closed
hirohe opened this issue Dec 14, 2023 · 5 comments · Fixed by #1673
Closed

bug(linter): some text in js file cause panic (byte index 8 is not a char boundary) #1671

hirohe opened this issue Dec 14, 2023 · 5 comments · Fixed by #1673
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers P-high Priority - High

Comments

@hirohe
Copy link

hirohe commented Dec 14, 2023

a js file contains line console.error('\x1B[41;37mpackage.json文件没有改动,禁止提交package-lock.json \x1B[0m');, the file is utf-8 and has ANSI escape sequences and zh-cn characters.

when execute the oxlint command:

oxlint -D all

it panic with message:

thread '<unnamed>' panicked at crates/oxc_linter/src/rules/unicorn/escape_case.rs:67:45:
byte index 55 is not a char boundary; it is inside '' (bytes 54..57) of `'\x1B[41;37mpackage.json文件没有改动,禁止提交package-lock.json \x1B[0m'`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

oxlint version is 0.0.20

@hirohe
Copy link
Author

hirohe commented Dec 14, 2023

run with RUST_BACKTRACE =full outputs:

thread '<unnamed>' panicked at crates/oxc_linter/src/rules/unicorn/escape_case.rs:67:45:
byte index 55 is not a char boundary; it is inside '' (bytes 54..57) of `'\x1B[41;37mpackage.json文件没有改动,禁止提交package-lock.json \x1B[0m'`
stack backtrace:
   0:        0x1005e447c - __mh_execute_header
   1:        0x10037dfec - __mh_execute_header
   2:        0x1005c3650 - __mh_execute_header
   3:        0x1005e7ce8 - __mh_execute_header
   4:        0x1005e7910 - __mh_execute_header
   5:        0x1005e87d8 - __mh_execute_header
   6:        0x1005e8370 - __mh_execute_header
   7:        0x1005e82dc - __mh_execute_header
   8:        0x1005e82d0 - __mh_execute_header
   9:        0x10064432c - __mh_execute_header
  10:        0x10038344c - __mh_execute_header
  11:        0x1006447e4 - __mh_execute_header
  12:        0x1004469ac - __mh_execute_header
  13:        0x100485618 - __mh_execute_header
  14:        0x100464948 - __mh_execute_header
  15:        0x10046104c - __mh_execute_header
  16:        0x100461240 - __mh_execute_header
  17:        0x10045eeac - __mh_execute_header
  18:        0x100461240 - __mh_execute_header
  19:        0x10045eeac - __mh_execute_header
  20:        0x100461240 - __mh_execute_header
  21:        0x10045eeac - __mh_execute_header
  22:        0x100461240 - __mh_execute_header
  23:        0x10045eeac - __mh_execute_header
  24:        0x1003df664 - __mh_execute_header
  25:        0x100658744 - __mh_execute_header
  26:        0x1005153ec - __mh_execute_header
  27:        0x1005150e4 - __mh_execute_header
  28:        0x1005e9a6c - __mh_execute_header
  29:        0x185f65034 - __pthread_joiner_wake

@Dunqing Dunqing added C-bug Category - Bug A-linter Area - Linter labels Dec 14, 2023
@Boshen
Copy link
Member

Boshen commented Dec 14, 2023

Marking as good first issue for anyone who wants to write this using proper Rust iterators, probably with let mut chars = s.chars(), .len_utf8(), peekable and friends.

fn check_case(value: &str, is_regex: bool) -> Option<String> {
let mut in_escape = false;
let chars: Vec<char> = value.chars().collect();
let mut result = String::with_capacity(value.len());
let mut index = 0;
while index < chars.len() {
let c = chars[index];
index += 1;
result.push(c);

@Boshen Boshen added good first issue Experience Level - Good for newcomers P-high Priority - High labels Dec 14, 2023
@Boshen
Copy link
Member

Boshen commented Dec 14, 2023

cc original author @RiESAEX and 🦶 🔫 killer @camc314 .

@RiESAEX
Copy link
Contributor

RiESAEX commented Dec 14, 2023

I should use index in bytes instead of in char, just calculate it in another variable.
but I don't know how to do this in a easy with iterator.

@Boshen
Copy link
Member

Boshen commented Dec 14, 2023

I should use index in bytes instead of in char, just calculate it in another variable. but I don't know how to do this in a easy with iterator.

Do you wanna give it a try and fix the panic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers P-high Priority - High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants