mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-01 04:32:01 -07:00
searcher: add option to disable BOM sniffing
This commit adds a new encoding feature where the -E/--encoding flag will now accept a value of 'none'. When given this value, all encoding related machinery is disabled and ripgrep will search the raw bytes of the file, including the BOM if it's present. Closes #1207, Closes #1208
This commit is contained in:
committed by
Andrew Gallant
parent
77439f99a4
commit
b00cd69a40
@@ -645,3 +645,35 @@ rgtest!(f1138_no_ignore_dot, |dir: Dir, mut cmd: TestCommand| {
|
||||
eqnice!("bar\nquux\n", cmd.arg("--no-ignore-dot").stdout());
|
||||
eqnice!("bar\n", cmd.arg("--ignore-file").arg(".fzf-ignore").stdout());
|
||||
});
|
||||
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1207
|
||||
//
|
||||
// Tests if without encoding 'none' flag null bytes are consumed by automatic
|
||||
// encoding detection.
|
||||
rgtest!(f1207_auto_encoding, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create_bytes(
|
||||
"foo",
|
||||
b"\xFF\xFE\x00\x62"
|
||||
);
|
||||
cmd.arg("-a").arg("\\x00").arg("foo");
|
||||
cmd.assert_exit_code(1);
|
||||
});
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1207
|
||||
//
|
||||
// Tests if encoding 'none' flag does treat file as raw bytes
|
||||
rgtest!(f1207_ignore_encoding, |dir: Dir, mut cmd: TestCommand| {
|
||||
// PCRE2 chokes on this test because it can't search invalid non-UTF-8
|
||||
// and the point of this test is to search raw UTF-16.
|
||||
if dir.is_pcre2() {
|
||||
return;
|
||||
}
|
||||
|
||||
dir.create_bytes(
|
||||
"foo",
|
||||
b"\xFF\xFE\x00\x62"
|
||||
);
|
||||
cmd.arg("--encoding").arg("none").arg("-a").arg("\\x00").arg("foo");
|
||||
eqnice!("\u{FFFD}\u{FFFD}\x00b\n", cmd.stdout());
|
||||
});
|
||||
|
Reference in New Issue
Block a user