fix: obsolete comment and add test for double-escaping hostname in nix_eval_homebrew_attr - #654
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
nix_eval_homebrew_attr
There was a problem hiding this comment.
Pull request overview
Updates nix_eval_homebrew_attr’s inline documentation to match the current implementation (which uses nix_string_literal), and strengthens the unit test to cover hostnames containing quote characters so regressions in quoting/escaping are caught early.
Changes:
- Replace an obsolete comment that referenced
serde_json::to_stringwith an accurate note aboutnix_string_literalproducing a fully quoted Nix string literal. - Extend the existing unit test to assert correct escaping when the hostname input contains quotes.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🎨 Storybook previewUpdated for e3c544b
|
📋 PR Overview
🔬 Coverage
|
12e5bd6 to
d994f95
Compare
d994f95 to
e3c544b
Compare
| // serde_json::to_string already wraps the hostname in quotes and escapes | ||
| // internals — do not also embed quote chars in the format string or we | ||
| // produce malformed attrs like .#darwinConfigurations.""host"".config… | ||
| // nix_string_literal returns a fully quoted Nix string literal, so the |
There was a problem hiding this comment.
Small nit on the wording: the attr path here isn't parsed as a Nix string literal. Nix's parseAttrPath (src/libexpr/attr-path.cc) understands "…" quoting but no backslash escapes:
} else if (*i == '"') {
++i;
while (1) {
if (i == s.end())
throw ParseError("missing closing quote in selection path '%1%'", s);
if (*i == '"')
break;
cur.push_back(*i++);
}So the \" cases in the test lock in output that nix rejects. Reproduced on nix 2.34.7 with a scratch flake that defines both attrs:
$ nix eval --json '.#darwinConfigurations."office\"mac".config.homebrew'
error: missing closing quote in selection path '...darwinConfigurations."office\"mac".config.homebrew'
$ nix eval --json '.#darwinConfigurations."\"quoted-host\"".config.homebrew'
error: flake ... does not provide attribute '...darwinConfigurations."\"quoted-host\"".config.homebrew'
Did you mean "quoted-host"?
Nothing breaks in practice — scutil --get LocalHostName can't produce quotes or backslashes — so this is purely about the comment and test not asserting something nix can't parse. Would it work to say just "nix_string_literal already wraps the hostname in quotes, so the format string must not add another pair" and drop the two escape assertions?






Summary
Saw this while reviewing #652 (which I think should be closed without merging, at least for the homebrew_adopt.rs change).
Test Plan
Enhanced unit test.
Docs