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

--files flag tries to interpret some arguments as regexes #326

Closed
n00bmind opened this issue Jan 16, 2017 · 13 comments
Closed

--files flag tries to interpret some arguments as regexes #326

n00bmind opened this issue Jan 16, 2017 · 13 comments
Labels
question An issue that is lacking clarity on one or more points.

Comments

@n00bmind
Copy link

Hi.
When trying to integrate your wonderful tool inside vim using 'let g:ctrlp_user_command = ...' I always got an error back because it seems that CtrlP always sends the path in windows format, which rg doesn't like, because apparently it tries to interpret the path as a regex (I checked this on the command line).

Strangely enough, even when setting 'shellslash' to on, the behaviour doesn't change (I'm gonna open an issue with CtrlP about this), so I had to resort to a custom batch script that substitutes the backslashes with forward slashes. Hacky to say the least.. :P

I think backslash support in Windows should be improved. I'm surprised nobody had problems with this before.. I don't know what the best approach would be, though. Maybe a specific switch or marker char that would mean "use this verbatim" or something?

@BurntSushi
Copy link
Owner

Thanks for reporting this!

I'll be honest, I have no idea what you're talking about or how to reproduce the problem. ripgrep should have no problems with Windows paths on Windows.

Could you please try to reproduce the issue outside of ctrlp/vim? Also, could you please include other basic information like your ripgrep version and environment? E.g., cygwin or native Windows?

@n00bmind
Copy link
Author

n00bmind commented Jan 16, 2017

Of course I tried in the command line. In fact that's how I found out / worked around the problem.
If I enter this in my terminal:
>rg --files .\repo\newrepo
all I get is "Literal '\n' not allowed".
If I do forward slashes instead I get the expected result.
I'm using ripgrep 0.3.2.

@BurntSushi
Copy link
Owner

It sounds like you're trying to type a file path for your regex?

Could you please provide more details about your environment? Are you in cygwin? A native console?

I've certainly used paths like foo\bar\baz on Windows before with ripgrep and it works just fine. (I don't have a Windows machine currently available to test. It will have to wait until I get home.)

@n00bmind
Copy link
Author

n00bmind commented Jan 17, 2017

This is a normal windows console, yes.
I'm merely providing a path as specified in this example from the 'usage' message:
rg [OPTIONS] --files [<path> ...]

@BurntSushi
Copy link
Owner

I can't reproduce this problem on ripgrep 0.4.0. I can run rg --files .\some\path and get the expected output. Note that rg .\repo\newrepo shows the error you've reported which is correct.

Can you please provide additional information?

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Jan 18, 2017
@ErrEoE
Copy link

ErrEoE commented Jan 18, 2017

This is my test result,
test

@n00bmind
Copy link
Author

Please note that I also used the '--files' flag, so ripgrep should interpret the rest as a path, isn't that right?
What do yo mean the error is "correct"?

@BurntSushi
Copy link
Owner

BurntSushi commented Jan 18, 2017

@chopsueysensei I'm trying to figure out the cause of the bug you're reporting. Sometimes the cause of bugs is that the report is either flawed in some way or I've misunderstood it (i.e., "user error" bugs). I'm trying to rule out that possibility.

I will be very clear. This is expected and correct output, because .\repo\newrepo is interpreted as a regex and not a file path:

$ rg '.\repo\newrepo'
Literal '\n' not allowed.

But this is unexpected and incorrect output because .\repo\newrepo is seemingly interpreted as a regex when it should be interpreted as a file path:

$ rg --files '.\repo\newrepo'
Literal '\n' not allowed.

However, I cannot reproduce this problem. Given the relative simplicity of the invocation, this led me to try to rule out user error.

I don't have any idea as to what's actually wrong yet. This bug doesn't make any sense to me.

@BurntSushi
Copy link
Owner

Interesting. While I couldn't reproduce this on Windows, I can seem to reproduce it on Linux:

$ rg --files '.\repo\newrepo'
Literal '\n' not allowed.

Weird. I should be able to track down the cause of the problem now.

@n00bmind
Copy link
Author

I understand your motivations, of course. But, as I noted, I was using the '--files' switch so indeed it seems as if it still wanted to interpret what should be a path as a regex instead.
I'm glad you have something to work on, now. Please let me know if there's anything I can try to help you track this down..

@speedyleion
Copy link

A slight workaround if you do want it to work in ctrl-p

    let g:ctrlp_user_command = 'rg --files --color never "" %s'

This will have a stray : The system cannot find the path specified. (os error 3) for the extra quotes but it will still build the list with the correct path.

@dfbrown
Copy link

dfbrown commented Feb 3, 2017

Another workaround is to add the -F flag so it treats patterns as literal strings instead of as regex. So for ctrl-p on windows I use

let g:ctrlp_user_command ='rg -F --files %s'

@BurntSushi BurntSushi changed the title RG inside Ctrlp/vim fails due to backslashes in Windows --files flag tries to interpret some arguments as regexes Feb 18, 2017
@BurntSushi
Copy link
Owner

@dfbrown Clever hack! This bug should be fixed in the next release. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

5 participants