This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 17dff76309 fix(core): percent-decode OperatorUri userinfo (#8845)
17dff76309 is described below
commit 17dff763093896d7bd9f8a14886d96c39869e425
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 17:43:01 2026 +0800
fix(core): percent-decode OperatorUri userinfo (#8845)
* fix(core): percent-decode OperatorUri userinfo
`Url::username()` and `Url::password()` report percent-encoded ASCII, so
`OperatorUri` handed encoded credentials to services while already decoding
`root` and query options. A URI such as
`smb://alice%40corp.com@host/share` yielded the username `alice%40corp.com`
instead of the one the URI author wrote.
Decode userinfo the same way as `root` and query options. An empty username
still maps to `None`.
* test(core): document plain userinfo case in OperatorUri test
Use a literal password containing `+` so the plain-credential case also
shows that percent-decoding does not turn `+` into a space.
---
core/core/src/types/operator/uri.rs | 66 +++++++++++++++++++++++++++++++++++--
core/services/smb/src/docs.md | 3 +-
2 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/core/core/src/types/operator/uri.rs
b/core/core/src/types/operator/uri.rs
index 1dd807dc4d..740fcc06cd 100644
--- a/core/core/src/types/operator/uri.rs
+++ b/core/core/src/types/operator/uri.rs
@@ -78,13 +78,21 @@ impl OperatorUri {
options.insert(key, value);
}
+ // `Url` reports userinfo in percent-encoded form, so decode it the
same
+ // way as `root` and query options.
let username = if url.username().is_empty() {
None
} else {
- Some(url.username().to_string())
+ Some(
+ percent_decode_str(url.username())
+ .decode_utf8_lossy()
+ .into_owned(),
+ )
};
- let password = url.password().map(|pwd| pwd.to_string());
+ let password = url
+ .password()
+ .map(|encoded|
percent_decode_str(encoded).decode_utf8_lossy().into_owned());
let authority = url.host_str().filter(|host|
!host.is_empty()).map(|host| {
if let Some(port) = url.port() {
@@ -337,4 +345,58 @@ mod tests {
assert_eq!(uri.password(), Some("secret"));
assert_eq!(uri.root(), Some("path"));
}
+
+ #[test]
+ fn parse_uri_decodes_percent_encoded_userinfo() {
+ let uri = OperatorUri::new(
+
"https://alice%40corp.com:p%40ss%2fw%3ard%[email protected]:8443/path%20dir",
+ Vec::<(String, String)>::new(),
+ )
+ .unwrap();
+
+ assert_eq!(uri.authority(), Some("example.com:8443"));
+ assert_eq!(uri.username(), Some("[email protected]"));
+ assert_eq!(uri.password(), Some("p@ss/w:rd%1"));
+ assert_eq!(uri.root(), Some("path dir"));
+ }
+
+ #[test]
+ fn parse_uri_with_password_only_keeps_username_none() {
+ let uri = OperatorUri::new(
+ "https://:only%[email protected]/",
+ Vec::<(String, String)>::new(),
+ )
+ .unwrap();
+
+ assert_eq!(uri.username(), None);
+ assert_eq!(uri.password(), Some("only#pass"));
+ assert_eq!(uri.root(), None);
+ }
+
+ #[test]
+ fn parse_uri_with_empty_password_keeps_username() {
+ // `Url` normalizes `alice:@example.com` to `[email protected]`, so an
+ // empty password is reported as `None` instead of `Some("")`.
+ let uri = OperatorUri::new(
+ "https://alice:@example.com/",
+ Vec::<(String, String)>::new(),
+ )
+ .unwrap();
+
+ assert_eq!(uri.username(), Some("alice"));
+ assert_eq!(uri.password(), None);
+ }
+
+ #[test]
+ fn parse_uri_keeps_plain_userinfo_unchanged() {
+ let uri = OperatorUri::new(
+ "https://alice:[email protected]/share",
+ Vec::<(String, String)>::new(),
+ )
+ .unwrap();
+
+ assert_eq!(uri.username(), Some("alice"));
+ assert_eq!(uri.password(), Some("pl+ain-pass"));
+ assert_eq!(uri.root(), Some("share"));
+ }
}
diff --git a/core/services/smb/src/docs.md b/core/services/smb/src/docs.md
index b9926af67c..bc1f8cd3bd 100644
--- a/core/services/smb/src/docs.md
+++ b/core/services/smb/src/docs.md
@@ -35,6 +35,7 @@ fn build_operator() -> Result<Operator> {
```
The URI authority sets `endpoint`, the first path component sets `share`, and
-the remaining path sets `root`. A `root` option is preserved when the URI
+the remaining path sets `root`. User information is percent-decoded, so encode
+reserved characters such as `@` and `:` as `%40` and `%3A`. A `root` option is
preserved when the URI
specifies only the share. Explicit options take precedence over credentials
embedded in the URI.