Skip to content

Commit 3a37ffa

Browse files
committed
Use compressed
1 parent a24c247 commit 3a37ffa

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

dsc/tests/dsc_functions.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ Describe 'tests for function expressions' {
11461146
@{ base = 'https://example.com/path'; relative = 'http://different.com/path'; expected = 'http://different.com/path' }
11471147
@{ base = 'https://user:pass@example.com/'; relative = 'path'; expected = 'https://user:pass@example.com/path' }
11481148
@{ base = 'https://example.com/'; relative = 'café/file.txt'; expected = 'https://example.com/caf%C3%A9/file.txt' }
1149-
@{ base = 'https://[::1]/'; relative = 'path'; expected = 'https://[0000:0000:0000:0000:0000:0000:0000:0001]/path' }
1150-
@{ base = 'https://[2001:db8::1]/'; relative = 'api/v1'; expected = 'https://[2001:0DB8:0000:0000:0000:0000:0000:0001]/api/v1' }
1151-
@{ base = 'https://[2001:db8::1]:8080/'; relative = 'api'; expected = 'https://[2001:0DB8:0000:0000:0000:0000:0000:0001]:8080/api' }
1149+
@{ base = 'https://[::1]/'; relative = 'path'; expected = 'https://[::1]/path' }
1150+
@{ base = 'https://[2001:db8::1]/'; relative = 'api/v1'; expected = 'https://[2001:db8::1]/api/v1' }
1151+
@{ base = 'https://[2001:db8::1]:8080/'; relative = 'api'; expected = 'https://[2001:db8::1]:8080/api' }
11521152
@{ base = 'http://192.168.1.1/'; relative = 'api/v1'; expected = 'http://192.168.1.1/api/v1' }
11531153
) {
11541154
param($base, $relative, $expected)

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rust_i18n::t;
88
use serde_json::Value;
99
use super::Function;
1010
use url::Url;
11-
use std::net::Ipv6Addr;
1211

1312
#[derive(Debug, Default)]
1413
pub struct Uri {}
@@ -52,21 +51,7 @@ impl Function for Uri {
5251
let result = base.join(relative_uri)
5352
.map_err(|e| DscError::Parser(format!("{}: {}", t!("functions.uri.invalidRelativeUri"), e)))?;
5453

55-
let final_result = if let Some(url::Host::Ipv6(ipv6_addr)) = result.host() {
56-
let segments = ipv6_addr.segments();
57-
let expanded = format!("{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}",
58-
segments[0], segments[1], segments[2], segments[3],
59-
segments[4], segments[5], segments[6], segments[7]
60-
);
61-
62-
let addr = Ipv6Addr::from(segments);
63-
let compressed = addr.to_string();
64-
result.to_string().replace(&compressed, &expanded)
65-
} else {
66-
result.to_string()
67-
};
68-
69-
Ok(Value::String(final_result))
54+
Ok(Value::String(result.to_string()))
7055
}
7156
}
7257

@@ -228,23 +213,23 @@ mod tests {
228213
fn test_uri_ipv6_localhost() {
229214
let mut parser = Statement::new().unwrap();
230215
let result = parser.parse_and_execute("[uri('https://[::1]/', 'path')]", &Context::new()).unwrap();
231-
// IPv6 should be expanded to match .NET behavior
232-
assert_eq!(result, "https://[0000:0000:0000:0000:0000:0000:0000:0001]/path");
216+
// IPv6 uses compressed format (standard representation)
217+
assert_eq!(result, "https://[::1]/path");
233218
}
234219

235220
#[test]
236221
fn test_uri_ipv6_address() {
237222
let mut parser = Statement::new().unwrap();
238223
let result = parser.parse_and_execute("[uri('https://[2001:db8::1]/', 'api/v1')]", &Context::new()).unwrap();
239-
// IPv6 should be expanded to match .NET behavior
240-
assert_eq!(result, "https://[2001:0DB8:0000:0000:0000:0000:0000:0001]/api/v1");
224+
// IPv6 uses compressed format (standard representation)
225+
assert_eq!(result, "https://[2001:db8::1]/api/v1");
241226
}
242227

243228
#[test]
244229
fn test_uri_ipv6_with_port() {
245230
let mut parser = Statement::new().unwrap();
246231
let result = parser.parse_and_execute("[uri('https://[2001:db8::1]:8080/', 'api')]", &Context::new()).unwrap();
247-
assert_eq!(result, "https://[2001:0DB8:0000:0000:0000:0000:0000:0001]:8080/api");
232+
assert_eq!(result, "https://[2001:db8::1]:8080/api");
248233
}
249234

250235
#[test]

0 commit comments

Comments
 (0)