diff options
author | lesnyrumcajs <lesny.rumcajs@gmail.com> | 2019-03-04 17:18:45 +0100 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2019-04-06 10:35:08 -0400 |
commit | 5962abc4655a0f07ece6fc6bd45142e8ee1cab0c (patch) | |
tree | 56b1f051f3e803cd24aa2d980c3edcf765756bda /tests | |
parent | 1604a18db3d896514e1d536781810642de4b31c1 (diff) |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/feature.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/feature.rs b/tests/feature.rs index 1e7ecc48..d7b343f1 100644 --- a/tests/feature.rs +++ b/tests/feature.rs @@ -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()); +}); |