fix(converter): escape quotes (#1790)
This commit is contained in:
parent
f6fa521313
commit
60ffd58b1e
4 changed files with 54 additions and 7 deletions
|
|
@ -16,7 +16,8 @@ fn pane_line(
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut pane_line = format!("pane");
|
let mut pane_line = format!("pane");
|
||||||
if let Some(pane_name) = pane_name {
|
if let Some(pane_name) = pane_name {
|
||||||
pane_line.push_str(&format!(" name=\"{}\"", pane_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
pane_line.push_str(&format!(" name={:?}", pane_name));
|
||||||
}
|
}
|
||||||
if let Some(split_size) = split_size {
|
if let Some(split_size) = split_size {
|
||||||
pane_line.push_str(&format!(" size={}", split_size));
|
pane_line.push_str(&format!(" size={}", split_size));
|
||||||
|
|
@ -38,7 +39,8 @@ fn tab_line(
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut pane_line = format!("tab");
|
let mut pane_line = format!("tab");
|
||||||
if let Some(pane_name) = pane_name {
|
if let Some(pane_name) = pane_name {
|
||||||
pane_line.push_str(&format!(" name=\"{}\"", pane_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
pane_line.push_str(&format!(" name={:?}", pane_name));
|
||||||
}
|
}
|
||||||
if let Some(split_size) = split_size {
|
if let Some(split_size) = split_size {
|
||||||
pane_line.push_str(&format!(" size={}", split_size));
|
pane_line.push_str(&format!(" size={}", split_size));
|
||||||
|
|
@ -61,7 +63,8 @@ fn pane_line_with_children(
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut pane_line = format!("pane");
|
let mut pane_line = format!("pane");
|
||||||
if let Some(pane_name) = pane_name {
|
if let Some(pane_name) = pane_name {
|
||||||
pane_line.push_str(&format!(" name=\"{}\"", pane_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
pane_line.push_str(&format!(" name={:?}", pane_name));
|
||||||
}
|
}
|
||||||
if let Some(split_size) = split_size {
|
if let Some(split_size) = split_size {
|
||||||
pane_line.push_str(&format!(" size={}", split_size));
|
pane_line.push_str(&format!(" size={}", split_size));
|
||||||
|
|
@ -85,7 +88,8 @@ fn pane_command_line(
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut pane_line = format!("pane command={:?}", command);
|
let mut pane_line = format!("pane command={:?}", command);
|
||||||
if let Some(pane_name) = pane_name {
|
if let Some(pane_name) = pane_name {
|
||||||
pane_line.push_str(&format!(" name=\"{}\"", pane_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
pane_line.push_str(&format!(" name={:?}", pane_name));
|
||||||
}
|
}
|
||||||
if let Some(split_size) = split_size {
|
if let Some(split_size) = split_size {
|
||||||
pane_line.push_str(&format!(" size={}", split_size));
|
pane_line.push_str(&format!(" size={}", split_size));
|
||||||
|
|
@ -108,7 +112,8 @@ fn tab_line_with_children(
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut pane_line = format!("tab");
|
let mut pane_line = format!("tab");
|
||||||
if let Some(pane_name) = pane_name {
|
if let Some(pane_name) = pane_name {
|
||||||
pane_line.push_str(&format!(" name=\"{}\"", pane_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
pane_line.push_str(&format!(" name={:?}", pane_name));
|
||||||
}
|
}
|
||||||
if let Some(split_size) = split_size {
|
if let Some(split_size) = split_size {
|
||||||
pane_line.push_str(&format!(" size={}", split_size));
|
pane_line.push_str(&format!(" size={}", split_size));
|
||||||
|
|
@ -218,7 +223,9 @@ fn stringify_template(
|
||||||
command_from_yaml
|
command_from_yaml
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| format!("\"{}\"", s))
|
// we use debug print here so that quotes and backslashes will be
|
||||||
|
// escaped
|
||||||
|
.map(|s| format!("{:?}", s))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(" ")
|
.join(" ")
|
||||||
));
|
));
|
||||||
|
|
@ -315,7 +322,8 @@ pub fn layout_yaml_to_layout_kdl(raw_yaml_layout: &str) -> Result<String, String
|
||||||
kdl_layout.push_str("\n}");
|
kdl_layout.push_str("\n}");
|
||||||
let layout_config = config_yaml_to_config_kdl(raw_yaml_layout, true)?;
|
let layout_config = config_yaml_to_config_kdl(raw_yaml_layout, true)?;
|
||||||
if let Some(session_name) = layout_from_yaml.session.name {
|
if let Some(session_name) = layout_from_yaml.session.name {
|
||||||
kdl_layout.push_str(&format!("\nsession_name \"{}\"", session_name));
|
// we use debug print here so that quotes and backslashes will be escaped
|
||||||
|
kdl_layout.push_str(&format!("\nsession_name {:?}", session_name));
|
||||||
if let Some(attach_to_session) = layout_from_yaml.session.attach {
|
if let Some(attach_to_session) = layout_from_yaml.session.attach {
|
||||||
kdl_layout.push_str(&format!("\nattach_to_session {}", attach_to_session));
|
kdl_layout.push_str(&format!("\nattach_to_session {}", attach_to_session));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,3 +140,19 @@ fn properly_convert_layout_example_4() -> Result<(), String> {
|
||||||
assert_snapshot!(format!("{}", kdl_config));
|
assert_snapshot!(format!("{}", kdl_config));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn properly_convert_layout_with_command_quoted_args() -> Result<(), String> {
|
||||||
|
let fixture = PathBuf::from(format!(
|
||||||
|
"{}/src/old_config_converter/unit/fixtures/old_yaml_layout_with_quoted_args.yaml",
|
||||||
|
env!("CARGO_MANIFEST_DIR")
|
||||||
|
));
|
||||||
|
let mut handle = File::open(&fixture).map_err(|e| format!("{}", e))?;
|
||||||
|
let mut raw_config_file = String::new();
|
||||||
|
handle
|
||||||
|
.read_to_string(&mut raw_config_file)
|
||||||
|
.map_err(|e| format!("{}", e))?;
|
||||||
|
let kdl_config = layout_yaml_to_layout_kdl(&raw_config_file)?;
|
||||||
|
assert_snapshot!(format!("{}", kdl_config));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
tabs:
|
||||||
|
- direction: Vertical
|
||||||
|
parts:
|
||||||
|
- direction: Vertical
|
||||||
|
run:
|
||||||
|
command: {cmd: bash, args: ["-c", "exec bash --init-file <(echo \"echo hi\") -i"]}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
source: zellij-client/src/old_config_converter/./unit/convert_layout_tests.rs
|
||||||
|
assertion_line: 156
|
||||||
|
expression: "format!(\"{}\", kdl_config)"
|
||||||
|
---
|
||||||
|
layout {
|
||||||
|
default_tab_template {
|
||||||
|
children
|
||||||
|
}
|
||||||
|
tab split_direction="Vertical" {
|
||||||
|
pane split_direction="Vertical" {
|
||||||
|
pane command="bash" {
|
||||||
|
args "-c" "exec bash --init-file <(echo \"echo hi\") -i"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue