Skip to content

Commit

Permalink
Fixes #26151: UTF-8 chars are HTML escaped when used in policy variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdall committed Jan 10, 2025
1 parent a30d950 commit 8a16377
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 98 deletions.
38 changes: 19 additions & 19 deletions policies/rudderc/src/backends/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,22 +377,22 @@ mod tests {
assert_eq!(res, r);

let c = "${var}";
let r = "([Rudder.Condition]::canonify([Rudder.Datastate]::Render('{{' + @'\n\
let r = "([Rudder.Condition]::canonify([Rudder.Datastate]::Render('{{{' + @'\n\
vars.var\n\
'@ + '}}')))";
'@ + '}}}')))";
let res = canonify_condition(c).unwrap();
assert_eq!(res, r);

let c = "${my_cond}.debian|${sys.${plouf}}";
let r = r#"([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{' + @'
let r = r#"([Rudder.Condition]::canonify(([Rudder.Datastate]::Render('{{{' + @'
vars.my_cond
'@ + '}}')) + @'
'@ + '}}}')) + @'
.debian|
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.
'@ + [Rudder.Datastate]::Render('{{' + @'
'@ + [Rudder.Datastate]::Render('{{{' + @'
vars.plouf
'@ + '}}') + '}}'))))"#;
'@ + '}}}') + '}}}'))))"#;
let res = canonify_condition(c).unwrap();
assert_eq!(res, r);
}
Expand Down Expand Up @@ -463,9 +463,9 @@ a simple test
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.plouf.plouf
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand All @@ -480,9 +480,9 @@ vars.plouf.plouf
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.technique_id.param1
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand All @@ -497,9 +497,9 @@ vars.technique_id.param1
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.plouf.param1
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand All @@ -514,9 +514,9 @@ vars.plouf.param1
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.param1or2
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand All @@ -531,9 +531,9 @@ vars.param1or2
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.host
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand All @@ -548,9 +548,9 @@ vars.sys.host
assert_eq!(
"@'
a less simple
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.const.n
'@ + '}}')) + @'
'@ + '}}}')) + @'
test
'@",
parameter_fmt(&&m_param, &t_id, &t_params).unwrap()
Expand Down
56 changes: 28 additions & 28 deletions policies/rudderc/src/ir/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn known_vars() -> &'static serde_yaml::Value {
}

fn nustache_render(s: &str) -> String {
format!("[Rudder.Datastate]::Render('{{{{' + {} + '}}}}')", s)
format!("[Rudder.Datastate]::Render('{{{{{{' + {} + '}}}}}}')", s)
}

/// Rudder variable expression.
Expand Down Expand Up @@ -806,9 +806,9 @@ mod tests {
a.fmt(Target::Windows),
r###"@'
/bin/true "#
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.node.inventory.os.fullName
'@ + '}}')) + @'
'@ + '}}}')) + @'
"
'@"###
);
Expand All @@ -820,18 +820,18 @@ vars.node.inventory.os.fullName
assert_eq!(b.fmt(Target::Unix), "${node.properties[a][b]}");
assert_eq!(
b.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.a.b
'@ + '}}')"#
'@ + '}}}')"#
);

let c: Expression = Expression::Sys(vec![Expression::Scalar("host".to_string())]);
assert_eq!(c.fmt(Target::Unix), "${sys.host}");
assert_eq!(
c.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.sys.host
'@ + '}}')"#
'@ + '}}}')"#
);

let cc: Expression = Expression::Sequence(vec![Expression::Scalar("host".to_string())]);
Expand All @@ -850,13 +850,13 @@ host
assert_eq!(d.fmt(Target::Unix), "${node.properties[inner${sys.host}]}");
assert_eq!(
d.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.
'@ + @'
inner
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.host
'@ + '}}')) + '}}')"#
'@ + '}}}')) + '}}}')"#
);

let dd = Expression::NodeProperty(vec![Expression::Sequence(vec![
Expand All @@ -867,15 +867,15 @@ vars.sys.host
])]);
assert_eq!(
dd.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.
'@ + @'
inner
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.
'@ + @'
host
'@ + '}}')) + '}}')"#
'@ + '}}}')) + '}}}')"#
);
assert_eq!(dd.fmt(Target::Unix), "${node.properties[inner${sys.host}]}");

Expand All @@ -886,15 +886,15 @@ host
assert_eq!(ee.fmt(Target::Unix), "${node.properties[interfaces][eth0]}");
assert_eq!(
ee.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.
'@ + @'
interfaces
'@ + @'
.
'@ + @'
eth0
'@ + '}}')"#
'@ + '}}}')"#
);

let e = Expression::NodeProperty(vec![
Expand All @@ -914,29 +914,29 @@ eth0
]);
assert_eq!(
e.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.node.properties.
'@ + @'
inner
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.
'@ + @'
host
'@ + '}}')) + ([Rudder.Datastate]::Render('{{' + @'
'@ + '}}}')) + ([Rudder.Datastate]::Render('{{{' + @'
vars.sys.
'@ + @'
interfaces
'@ + @'
.
'@ + @'
eth0
'@ + '}}')) + '}}')) + @'
'@ + '}}}')) + '}}}')) + @'
.
'@ + @'
tutu
'@ + '}}')"#
'@ + '}}}')"#
);
assert_eq!(
e.fmt(Target::Unix),
Expand All @@ -950,13 +950,13 @@ tutu
])])]);
assert_eq!(
e.fmt(Target::Windows),
r#"([Rudder.Datastate]::Render('{{' + @'
r#"([Rudder.Datastate]::Render('{{{' + @'
vars.sys.
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.
'@ + @'
host
'@ + '}}')) + '}}'))"#
'@ + '}}}')) + '}}}'))"#
.to_string()
);
let e = Expression::GenericVar(vec![
Expand All @@ -965,9 +965,9 @@ host
]);
assert_eq!(
e.fmt(Target::Windows),
r#"[Rudder.Datastate]::Render('{{' + @'
r#"[Rudder.Datastate]::Render('{{{' + @'
vars.bundle.plouf.key
'@ + '}}')"#
'@ + '}}}')"#
.to_string()
);
assert_eq!(e.fmt(Target::Unix), "${bundle.plouf[key]}".to_string());
Expand All @@ -980,9 +980,9 @@ vars.bundle.plouf.key
f.fmt(Target::Windows),
r#"@'
bundle.plouf is
'@ + ([Rudder.Datastate]::Render('{{' + @'
'@ + ([Rudder.Datastate]::Render('{{{' + @'
vars.bundle.plouf
'@ + '}}'))"#
'@ + '}}}'))"#
.to_string()
);
}
Expand Down
Loading

0 comments on commit 8a16377

Please sign in to comment.