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

nix search throws incorrect error about empty regex for many inputs #3047

Open
lilyball opened this issue Aug 16, 2019 · 4 comments
Open

nix search throws incorrect error about empty regex for many inputs #3047

lilyball opened this issue Aug 16, 2019 · 4 comments
Labels

Comments

@lilyball
Copy link
Member

When I run nix search with anything beyond the absolute most basic args, it tends to throw an error saying "An empty regex is not allowed in the POSIX grammar". This is extremely bizarre as my input is not empty.

Here are some failing examples:

  • nix search '\youtube'
  • nix search '(?:jazzy)'
  • nix search 'foo(?i)bar'

All of these are valid regular expressions and should be accepted.

The first example is rather curious because putting a \y anywhere else works, and the leading slash works if it's actually escaping a magic char (like \.foo), it's only when there's a leading slash followed by a non-magic character that it gives this bogus error.

  • system: "x86_64-darwin"
  • host os: Darwin 18.7.0, macOS 10.14.6
  • multi-user?: no
  • sandbox: no
  • version: nix-env (Nix) 2.2.2
  • channels(eridius): "nixpkgs-19.09pre186574.88d9f776091"
  • nixpkgs: /Users/eridius/.nix-defexpr/channels/nixpkgs
@lilyball
Copy link
Member Author

I did some digging and it looks like you're using C++11 regexes, and this exception is actually coming from libc++ on Darwin. (?:foo) and (?i) are both actually "enhanced" extended regex features, though that doesn't explain the error message, nor does it explain the issue with \youtube (extended REs should interpret \youtube identically to youtube). In addition, some other "enhanced" syntaxes like .*? or you\> are accepted, though AFAICT it's completely ignoring the enhanced instruction (e.g. you\> is matching the word "your" even though it's not supposed to).

Also, curiously, the use of [[:>:]] produces a "mismatched [ and ]" error even though this is part of the documented extended RE syntax from man re_format.

Given the desire to use extended regexes, and the fact that libc++ seems to have bugs with this syntax, nix search may want to fall back to the C regcomp() API instead since that handles \youtube and you[[:<:]] just fine.

While we're at it, I'd also recommend adding in the "enhanced" flag, because we don't need portable regexes here (and if you want portable you can still just use the non-enhanced subset).

@lilyball
Copy link
Member Author

lilyball commented Aug 16, 2019

Interestingly, nix search 'you[[:>:]]' gives a different error than I get in my C++ test code with the same input. My test code says "The expression contained an invalid character class name" but nix search says "The expression contained mismatched [ and ]."

@stale
Copy link

stale bot commented Feb 18, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 18, 2021
@stale
Copy link

stale bot commented Apr 28, 2022

I closed this issue due to inactivity. → More info

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

No branches or pull requests

2 participants