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

lib.showOption doesn't quote attributes with periods #152649

Closed
lilyball opened this issue Dec 30, 2021 · 2 comments · Fixed by #194035
Closed

lib.showOption doesn't quote attributes with periods #152649

lilyball opened this issue Dec 30, 2021 · 2 comments · Fixed by #194035
Labels
0.kind: bug Something is broken

Comments

@lilyball
Copy link
Member

Describe the bug

lib.showOption doesn't quote attributes containing periods, so the output is identical for e.g. [ "a.b" ] and [ "a" "b" ].

Steps To Reproduce

Steps to reproduce the behavior:

  1. lib.showOption [ "a" "b.c" "d" ]

Expected behavior

It should return ''a."b.c".d''. Instead it returns ''a.b.c.d''.

Additional context

It also doesn't include quotes for components containing other non-attribute-valid chars such as spaces. This is more of an aesthetic issue as a.b c.d is unambiguous, though it bothers me. Not quoting components containing periods is a correctness issue.

Right now it calls lib.strings.escapeNixString and checks if the output is identical to "${part}". It does have comments explaining that it allows options starting with digits, as well as placeholders like * and <name>. This means it can't just use lib.strings.escapeNixIdentifier. But it could still be a bit smarter about this, inlining lib.strings.escapeNixIdentifier and then modifying the regex to allow these additional values.

My suggestion for such a regex is something like "([^[:punct:][:space:]]|['_<>*-])+". This way most punctuation and all whitespace will cause quoting but it will still allow * and <name>. Alternatively it could be more conservative and only quote for spaces and periods, but it seems more reasonable to me to quote for arbitrary punctuation as well.

Notify maintainers

@jtojnar @grahamc @LnL7 @infinisil

Metadata

nix run nixpkgs#nix-info -- -m
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.2.0, macOS 12.1`
 - multi-user?: `yes`
 - sandbox: `relaxed`
 - version: `nix-env (Nix) 2.5.1`
 - channels(lily): `"darwin, home-manager"`
 - channels(root): `"nixpkgs-21.11pre330171.92204897f3d"`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`
@lilyball lilyball added the 0.kind: bug Something is broken label Dec 30, 2021
@lilyball
Copy link
Member Author

Note that my suggested regex takes advantage of the fact that builtins.match doesn't seem to be unicode-aware, in that builtins.match "[^[:punct:]]+" "«" succeeds. This seems like a bug, so if Nix ever gains unicode support here, this might have to be modified to explicitly allow either common placeholder chars or just all non-ASCII chars.

@infinisil
Copy link
Member

This relates to #82461 (comment) and #85241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants