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

Unrecognised escape sequence (\/) #663

Closed
wolf99 opened this issue Jun 25, 2022 · 5 comments
Closed

Unrecognised escape sequence (\/) #663

wolf99 opened this issue Jun 25, 2022 · 5 comments

Comments

@wolf99
Copy link

wolf99 commented Jun 25, 2022

I am trying to add a .lycheeignore file that will ignore https://www.godaddy.com/. (Because it returns infinite HTTP 302s as it tries to redirect to a localized page).

I'd like to be able to ignore even if the trailing sforward slash is present or not.
So I construct the following regex:

godaddy\.com(\/)?$

git-ecosystem/git-credential-manager@e848ba8

However, lychee appears to barf on this regex:

+ eval lychee --format markdown --output /tmp/lychee/out.md --user-agent '"Mozilla/5.0' '(Windows' NT '10.0;' 'Win64;' 'x64)' AppleWebKit/[53](https://github.com/GitCredentialManager/git-credential-manager/runs/7055448925?check_suite_focus=true#step:3:56)7.36 '(KHTML,' like 'Gecko)' Chrome/100.0.4896.75 'Safari/537.36"' --no-progress .
++ lychee --format markdown --output /tmp/lychee/out.md --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36' --no-progress .
Error: regex parse error:
    godaddy\.com(\/)?$
                 ^^
error: unrecognized escape sequence
+ exit_code=1

I've stared at this for about 30 mins on regex101.com, but I cannot see how this is wrong regex.

See: https://regex101.com/r/P1B4wT/1

image

I tried with a non-capturing group also, but no change: git-ecosystem/git-credential-manager@bc76c6e

@mre
Copy link
Member

mre commented Jun 26, 2022

You also need to escape the escape character:

godaddy\.com(\\/)?$

Explanation: the first backslash is because of the extraction of the backslash character from the text file (it's a special character for text), the second is the actual regex escape.

BTW if you want to ignore all godaddy domains you can just use godaddy\.com as a pattern. Your regex currently just includes the homepage because of the $ at the end.

@mre mre transferred this issue from lycheeverse/lychee-action Jun 26, 2022
@mre
Copy link
Member

mre commented Jun 26, 2022

Moved to the main lychee repo, because the error is reproducible without the action.

@mre
Copy link
Member

mre commented Jun 26, 2022

I'm gonna close this as resolved. Feel free to reopen in case it doesn't work. 😊

@mre mre closed this as completed Jun 26, 2022
@wolf99
Copy link
Author

wolf99 commented Jun 26, 2022

Not sure I grok the explanation, but it works 🤷
Thanks!

@mre
Copy link
Member

mre commented Jun 26, 2022

Backslash is commonly associated with escaping the next character in a string.
I thought it fails because it should be escaped once for the string literal and once for the regex as described here.

However I think in reality it's because \/ is a no-op escape in the Rust regex crate (it does nothing as / doesn't need to be escaped) and that is not allowed. See the discussion here.
That means you can also just use

godaddy\.com/?$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants