Skip to content

refactor: feature names inside double quotes if containing a . #3594

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mrswastik-robot
Copy link
Contributor

fixes #3171

Code refactored is in table_name.rs:

if feature_str.contains('.') {
    parts.push(format!("\"{}\"", feature_str).leak());
} else {
    parts.push(feature_str);
}

Had to use leak() otherwise I was facing lifetime error.
Also added a test case, it's passing.

@ruben-arts
Copy link
Contributor

It doesn't work with pixi add -f test.test bat as that will result in:

[feature.'"test'.'test"'.dependencies]
bat = "*"

@mrswastik-robot
Copy link
Contributor Author

It doesn't work with pixi add -f test.test bat as that will result in:

[feature.'"test'.'test"'.dependencies]
bat = "*"

sorry, @ruben-arts, my bad! is it because the quotes are being included in the string rather than being treated as delimiters? Using format!("\"{}\"", feature_str) inserts literal quotes into the string, but TOML treats them differently...
I guess the quoting is being handled by the toml_edit library

Copy link
Contributor

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for simplicity and reuse we could just have function or struct to escape a string? I assume there are more reasons to add quotes to keys?

@mrswastik-robot
Copy link
Contributor Author

Maybe for simplicity and reuse we could just have function or struct to escape a string? I assume there are more reasons to add quotes to keys?

Maybe for simplicity and reuse we could just have function or struct to escape a string? I assume there are more reasons to add quotes to keys?

Maybe for simplicity and reuse we could just have function or struct to escape a string? I assume there are more reasons to add quotes to keys?

yup I get the point, so should I write a generalised function like escape_toml_keys perhaps in a file like crates/pixi_manifest/src/utils/toml_utils.rs, that should work for characters that require esaping in TOML keys?

@baszalmstra
Copy link
Contributor

Makes sense!

@ruben-arts
Copy link
Contributor

pixi add -f test.test bat

Still results in:

[feature.'"test'.'test"'.dependencies]
bat = "*"

It would be good to add a simple integration test to figure out that the manifest can still be read after the pixi add command.

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

Successfully merging this pull request may close these issues.

Feature names are allowed to contain a . but causes a parser error after being added.
3 participants