Skip to content

Commit

Permalink
jj config list: escape keys
Browse files Browse the repository at this point in the history
Fixes jj-vcs#1322. There may be more places where keys need escaping, I'm not
completely sure.
  • Loading branch information
ilyagr committed May 21, 2024
1 parent 1f7c4ec commit c303527
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit c303527

Please sign in to comment.