Code Monkey home page Code Monkey logo

Comments (10)

BurntSushi avatar BurntSushi commented on June 8, 2024 2
$ echo 'fig
^mango'
fig
!!:s^mango

lolwut

from ripgrep.

BurntSushi avatar BurntSushi commented on June 8, 2024 1

Yeah, odd indeed. Here's mine:

$ printf '%b' "$s" | rg --trace -UF 'fig
^mango'
DEBUG|rg::flags::config|crates/core/flags/config.rs:41: /home/andrew/.ripgreprc: arguments loaded from config file: ["--max-columns-preview", "--colors=match:bg:0xff,0x7f,0x00", "--colors=match:fg:white", "--colors=line:none", "--colors=line:fg:magenta", "--colors=path:fg:green", "--type-add=got:*_test.go"]
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: duff
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy
apple fig
^mango banana

Where the regex is "(?:fig\n\\^mango)" is what I'd expect.

You seem to be having some kind of extra !!:s being inserted between the \n and the \^. I dunno where that is coming from. Can you try a different shell?

Okay, that made me try a different shell. I use zsh by default. So I dropped into bash:

[andrew@duff ripgrep] printf '%b' "$s" | rg --trace -UF 'fig
^mango'
DEBUG|rg::flags::config|crates/core/flags/config.rs:41: /home/andrew/.ripgreprc: arguments loaded from config file: ["--max-columns-preview", "--colors=match:bg:0xff,0x7f,0x00", "--colors=match:fg:white", "--colors=line:none", "--colors=line:fg:magenta", "--colors=path:fg:green", "--type-add=got:*_test.go"]
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: duff
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n!!:s\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy

This sadly therefore looks like something bash is doing. I haven't the faintest clue what it is. And I'm surprised by it, given that single quotes are being used here.

from ripgrep.

learnbyexample avatar learnbyexample commented on June 8, 2024 1

Oh! Didn't expect that! I'll try to check the bash bug list tomorrow. It feels like a regression, since this was working for me 3 years ago.

from ripgrep.

BurntSushi avatar BurntSushi commented on June 8, 2024

Interestingly, I cannot reproduce this:

$ s='apple fig\n^mango banana\n123 456\ndragon$\nunicorn\n'
$ printf '%b' "$s" | rg -UF 'banana
123'
^mango banana
123 456
$ printf '%b' "$s" | rg -UF 'fig
^mango'
apple fig
^mango banana

Can you re-run with --trace? That might show some information.

I can't make heads or tails of this. The search shouldn't care about ^.

from ripgrep.

learnbyexample avatar learnbyexample commented on June 8, 2024

Oh. I did wonder if there's something wrong/different on my machine. Here's the --trace output:

$ printf '%b' "$s" | rg -UF --trace 'fig
^mango'
DEBUG|rg::flags::parse|crates/core/flags/parse.rs:97: no extra arguments found from configuration file
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1099: using heuristics to determine whether to read from stdin or search ./ (is_readable_stdin=true, stdin_consumed=false, mode=Search(Standard))
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1112: heuristic chose to search stdin
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1260: found hostname for hyperlink configuration: abcd
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:1270: hyperlink format: ""
DEBUG|rg::flags::hiargs|crates/core/flags/hiargs.rs:174: using 1 thread(s)
DEBUG|grep_regex::config|crates/regex/src/config.rs:175: assembling HIR from 1 fixed string literals
TRACE|grep_regex::matcher|crates/regex/src/matcher.rs:66: final regex: "(?:fig\n!!:s\\^mango)"
TRACE|grep_regex::literal|crates/regex/src/literal.rs:59: skipping inner literal extraction, no line terminator is set
DEBUG|globset|crates/globset/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
TRACE|rg::search|crates/core/search.rs:254: <stdin>: binary detection: BinaryDetection(Convert(0))
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:728: generic reader: reading everything to heap for multiline
TRACE|grep_searcher::searcher|crates/searcher/src/searcher/mod.rs:732: generic reader: searching via multiline strategy

Final regex (?:fig\n!!:s\\^mango) seems very odd, compared to (?:banana\n123) and (?:fig\n\\^mango) (when I use $'fig\n^mango').

from ripgrep.

BurntSushi avatar BurntSushi commented on June 8, 2024

I posted about this on twitter, and it looks like some kind interaction substitution based on history. But the fact that it's happening inside a single quoted string suggests this might be a bash bug.

from ripgrep.

learnbyexample avatar learnbyexample commented on June 8, 2024

Discussion in the bug-bash group: https://lists.gnu.org/archive/html/bug-bash/2023-12/msg00064.html

from ripgrep.

BurntSushi avatar BurntSushi commented on June 8, 2024

Thanks for the follow-up! I read through that thread and I can't even tell whether they consider the behavior a bug or not. It sounds like they are just going to fix the docs?

from ripgrep.

learnbyexample avatar learnbyexample commented on June 8, 2024

I think they are going to fix it for single quotes (along with documentation update):

The quick substitution feature didn't pay attention to the quoting state,
however, and just translated the line into a standard history expansion,
which was then skipped. The fix is to have it inhibit quick substitution
the same way as other history expansions.

from ripgrep.

BurntSushi avatar BurntSushi commented on June 8, 2024

Yeah I saw that. But the other part of their message was "This is a standard form of history expansion, described in the man page." That confused me hah. Either way, quite interesting!

from ripgrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.