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

jj config list: escape keys #3725

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* When the working copy commit becomes immutable, a new one is automatically created on top of it
to avoid letting the user edit the immutable one.

* `jj config list` now properly escapes TOML keys (#1322).

## [0.17.1] - 2024-05-07

### Fixed bugs
Expand Down
7 changes: 6 additions & 1 deletion cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,19 @@ pub(crate) fn cmd_config(
}
}

fn toml_escape_key(key: String) -> String {
toml_edit::Key::from(key).to_string()
}

// AnnotatedValue will be cloned internally in the templater. If the cloning
// cost matters, wrap it with Rc.
fn config_template_language() -> GenericTemplateLanguage<'static, AnnotatedValue> {
type L = GenericTemplateLanguage<'static, AnnotatedValue>;
let mut language = L::new();
// "name" instead of "path" to avoid confusion with the source file path
language.add_keyword("name", |self_property| {
let out_property = self_property.map(|annotated| annotated.path.join("."));
let out_property = self_property
.map(|annotated| annotated.path.into_iter().map(toml_escape_key).join("."));
Ok(L::wrap_string(out_property))
});
language.add_keyword("value", |self_property| {
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fn test_config_list_table() {
x = true
y.foo = "abc"
y.bar = 123
"z"."with space"."function()" = 5
"#,
);
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "list", "test-table"]);
Expand All @@ -76,6 +77,7 @@ fn test_config_list_table() {
test-table.x=true
test-table.y.bar=123
test-table.y.foo="abc"
test-table.z."with space"."function()"=5
"###);
}

Expand Down