Skip to content

Commit e59d9e4

Browse files
committed
Change resourceId() to url encode the name
1 parent aa3ffc0 commit e59d9e4

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/dsc-lib/src/functions/resource_id.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ impl Function for ResourceId {
4242
}
4343
// ARM uses a slash separator, but here we use a colon which is not allowed for the type nor name
4444
result.push(':');
45-
// second argument is the name and must contain no slashes
45+
// second argument is the name and we url encode it to ensure no unexpected characters are present
4646
let resource_name = &args[1];
4747
if let Some(value) = resource_name.as_str() {
48-
if value.contains('/') {
49-
return Err(DscError::Function("resourceId".to_string(), t!("functions.resourceId.incorrectNameFormat").to_string()));
50-
}
51-
52-
result.push_str(value);
48+
let encoded = urlencoding::encode(value);
49+
result.push_str(&encoded);
5350
} else {
5451
return Err(DscError::Parser(t!("functions.resourceId.invalidSecondArgType").to_string()));
5552
}
@@ -85,10 +82,10 @@ mod tests {
8582
}
8683

8784
#[test]
88-
fn invalid_name() {
85+
fn valid_name_with_slashes() {
8986
let mut parser = Statement::new().unwrap();
90-
let result = parser.parse_and_execute("[resourceId('a','b/c')]", &Context::new());
91-
assert!(result.is_err());
87+
let result = parser.parse_and_execute("[resourceId('a','b/c')]", &Context::new()).unwrap();
88+
assert_eq!(result, "a:b%2Fc");
9289
}
9390

9491
#[test]

0 commit comments

Comments
 (0)