Skip to content

Commit 2819212

Browse files
committed
printer: tweak binary detection message format
This roughly matches similar changes made in GNU grep recently.
1 parent 810be0b commit 2819212

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ TBD
22
===
33
Unreleased changes. Release notes have not yet been written.
44

5+
In this release, a small tweak has been made to the output format when a binary
6+
file is detected. Previously, it looked like this:
7+
8+
```
9+
Binary file FOO matches (found "\0" byte around offset XXX)
10+
```
11+
12+
Now it looks like this:
13+
14+
```
15+
FOO: binary file matches (found "\0" byte around offset XXX)
16+
```
17+
518
Bug fixes:
619

720
* [BUG #1277](https://github.com/BurntSushi/ripgrep/issues/1277):

crates/printer/src/standard.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1358,25 +1358,24 @@ impl<'a, M: Matcher, W: WriteColor> StandardImpl<'a, M, W> {
13581358

13591359
let bin = self.searcher.binary_detection();
13601360
if let Some(byte) = bin.quit_byte() {
1361-
self.write(b"WARNING: stopped searching binary file ")?;
13621361
if let Some(path) = self.path() {
13631362
self.write_spec(self.config().colors.path(), path.as_bytes())?;
1364-
self.write(b" ")?;
1363+
self.write(b": ")?;
13651364
}
13661365
let remainder = format!(
1367-
"after match (found {:?} byte around offset {})\n",
1366+
"WARNING: stopped searching binary file after match \
1367+
(found {:?} byte around offset {})\n",
13681368
[byte].as_bstr(),
13691369
offset,
13701370
);
13711371
self.write(remainder.as_bytes())?;
13721372
} else if let Some(byte) = bin.convert_byte() {
1373-
self.write(b"Binary file ")?;
13741373
if let Some(path) = self.path() {
13751374
self.write_spec(self.config().colors.path(), path.as_bytes())?;
1376-
self.write(b" ")?;
1375+
self.write(b": ")?;
13771376
}
13781377
let remainder = format!(
1379-
"matches (found {:?} byte around offset {})\n",
1378+
"binary file matches (found {:?} byte around offset {})\n",
13801379
[byte].as_bstr(),
13811380
offset,
13821381
);

tests/binary.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rgtest!(after_match1_implicit, |dir: Dir, mut cmd: TestCommand| {
4040

4141
let expected = "\
4242
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
43-
WARNING: stopped searching binary file hay after match (found \"\\0\" byte around offset 9741)
43+
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 9741)
4444
";
4545
eqnice!(expected, cmd.stdout());
4646
});
@@ -53,7 +53,7 @@ rgtest!(after_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
5353

5454
let expected = "\
5555
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
56-
Binary file matches (found \"\\0\" byte around offset 9741)
56+
binary file matches (found \"\\0\" byte around offset 9741)
5757
";
5858
eqnice!(expected, cmd.stdout());
5959
});
@@ -64,7 +64,7 @@ rgtest!(after_match1_stdin, |_: Dir, mut cmd: TestCommand| {
6464

6565
let expected = "\
6666
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
67-
Binary file matches (found \"\\0\" byte around offset 9741)
67+
binary file matches (found \"\\0\" byte around offset 9741)
6868
";
6969
eqnice!(expected, cmd.pipe(HAY));
7070
});
@@ -85,7 +85,7 @@ rgtest!(after_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
8585

8686
let expected = "\
8787
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
88-
Binary file hay matches (found \"\\0\" byte around offset 9741)
88+
hay: binary file matches (found \"\\0\" byte around offset 9741)
8989
";
9090
eqnice!(expected, cmd.stdout());
9191
});
@@ -200,7 +200,7 @@ rgtest!(after_match2_implicit, |dir: Dir, mut cmd: TestCommand| {
200200

201201
let expected = "\
202202
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
203-
WARNING: stopped searching binary file hay after match (found \"\\0\" byte around offset 9741)
203+
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 9741)
204204
";
205205
eqnice!(expected, cmd.stdout());
206206
});
@@ -240,7 +240,7 @@ rgtest!(before_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
240240
cmd.args(&["--no-mmap", "-n", "Heaven", "hay"]);
241241

242242
let expected = "\
243-
Binary file matches (found \"\\0\" byte around offset 9741)
243+
binary file matches (found \"\\0\" byte around offset 9741)
244244
";
245245
eqnice!(expected, cmd.stdout());
246246
});
@@ -253,7 +253,7 @@ rgtest!(before_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
253253
cmd.args(&["--no-mmap", "-n", "--binary", "Heaven", "-g", "hay"]);
254254

255255
let expected = "\
256-
Binary file hay matches (found \"\\0\" byte around offset 9741)
256+
hay: binary file matches (found \"\\0\" byte around offset 9741)
257257
";
258258
eqnice!(expected, cmd.stdout());
259259
});
@@ -288,7 +288,7 @@ rgtest!(before_match2_explicit, |dir: Dir, mut cmd: TestCommand| {
288288
cmd.args(&["--no-mmap", "-n", "a medical student", "hay"]);
289289

290290
let expected = "\
291-
Binary file matches (found \"\\0\" byte around offset 9741)
291+
binary file matches (found \"\\0\" byte around offset 9741)
292292
";
293293
eqnice!(expected, cmd.stdout());
294294
});

tests/misc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ rgtest!(unrestricted3, |dir: Dir, mut cmd: TestCommand| {
788788
cmd.arg("-uuu").arg("foo");
789789

790790
let expected = "\
791-
Binary file hay matches (found \"\\0\" byte around offset 3)
791+
hay: binary file matches (found \"\\0\" byte around offset 3)
792792
";
793793
eqnice!(expected, cmd.stdout());
794794
});
@@ -1001,7 +1001,7 @@ rgtest!(binary_convert, |dir: Dir, mut cmd: TestCommand| {
10011001
cmd.arg("--no-mmap").arg("foo").arg("file");
10021002

10031003
let expected = "\
1004-
Binary file matches (found \"\\0\" byte around offset 3)
1004+
binary file matches (found \"\\0\" byte around offset 3)
10051005
";
10061006
eqnice!(expected, cmd.stdout());
10071007
});
@@ -1011,7 +1011,7 @@ rgtest!(binary_convert_mmap, |dir: Dir, mut cmd: TestCommand| {
10111011
cmd.arg("--mmap").arg("foo").arg("file");
10121012

10131013
let expected = "\
1014-
Binary file matches (found \"\\0\" byte around offset 3)
1014+
binary file matches (found \"\\0\" byte around offset 3)
10151015
";
10161016
eqnice!(expected, cmd.stdout());
10171017
});

0 commit comments

Comments
 (0)