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

empty pattern doesn't display utf8 #937

Closed
jbolila opened this issue Jun 3, 2018 · 2 comments · Fixed by #1017
Closed

empty pattern doesn't display utf8 #937

jbolila opened this issue Jun 3, 2018 · 2 comments · Fixed by #1017
Labels
bug A bug.

Comments

@jbolila
Copy link

jbolila commented Jun 3, 2018

What version of ripgrep are you using?

ripgrep 0.8.1
-SIMD -AVX

How did you install ripgrep?

cargo install ripgrep -f

What operating system are you using ripgrep on?

Linux Debian 9.

Describe your question, feature request, or bug.

On empty patterns utf8 strings aren't presented with the correct encode.

If this is a bug, what are the steps to reproduce the behavior?

❯ rg -S -n --color=always '' Cargo.toml
1:[package]
2:authors = ["Jo[0mo Bolila <j**>"]
..
❯ rg -S -n --color=always 'au' Cargo.toml
2:authors = ["João Bolila <j**>"]

Or with any utf8 content.

lotabout/skim#83

If this is a bug, what is the actual behavior?

Doesn't display correctly on empty patterns

If this is a bug, what is the expected behavior?

Display always like when has a pattern match.

Thanks!

@BurntSushi
Copy link
Owner

BurntSushi commented Jun 3, 2018

Initially, I couldn't reproduce this:

$ cat test1
ã
$ rg --color always '' test1
1:ã

On a hunch, I tried a different terminal emulator (specifically, xterm):

$ rg --color always '' test1
1:��

So that did the trick.

The specific problem here is that you're searching with an empty pattern, which matches at every position, even between UTF-8 code units. I suspect this itself might actually be a bug in the regex engine. A simple fix on ripgrep's side of things would be to simply not emit color escapes for zero width matches, since those color escapes aren't visually observable by humans. This would fix things because the reason why you're seeing bad output is presumably because there is a color escape sequence between UTF-8 code units, and your terminal emulator chokes on it. However, some folks are using ripgrep's color escapes to determine match locations, so I don't think I can make that change until ripgrep has a structured output feature.

So, you're pretty much stuck with this behavior for now. You might re-visit why it is you're feeding an empty pattern to ripgrep if you're looking for a workaround.

@BurntSushi
Copy link
Owner

I filed a bug against the regex engine. Fixing that would also fix this bug. rust-lang/regex#484

BurntSushi added a commit that referenced this issue Aug 19, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
BurntSushi added a commit that referenced this issue Aug 20, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants