mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Mitigate the poor interaction between ndots expansion and non-path strings (#13218)
# Description @hustcer reported that slashes were disappearing from external args since #13089: ``` $> ossutil ls oss://abc/b/c Error: invalid cloud url: "oss:/abc/b/c", please make sure the url starts with: "oss://" $> ossutil ls 'oss://abc/b/c' Error: oss: service returned error: StatusCode=403, ErrorCode=UserDisable, ErrorMessage="UserDisable", RequestId=66791EDEFE87B73537120838, Ec=0003-00000801, Bucket=abc, Object= ``` I narrowed this down to the ndots handling, since that does path parsing and path reconstruction in every case. I decided to change that so that it only activates if the string contains at least `...`, since that would be the minimum trigger for ndots, and also to not activate it if the string contains `://`, since it's probably undesirable for a URL. Kind of a hack, but I'm not really sure how else we decide whether someone wants ndots or not. # User-Facing Changes - bare strings not containing ndots are not modified - bare strings containing `://` are not modified # Tests + Formatting Added tests to prevent regression.
This commit is contained in:
@ -229,6 +229,38 @@ fn external_command_escape_args() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_command_ndots_args() {
|
||||
let actual = nu!(r#"
|
||||
nu --testbin cococo foo/. foo/.. foo/... foo/./bar foo/../bar foo/.../bar ./bar ../bar .../bar
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
if cfg!(windows) {
|
||||
// Windows is a bit weird right now, where if ndots has to fix something it's going to
|
||||
// change everything to backslashes too. Would be good to fix that
|
||||
r"foo/. foo/.. foo\..\.. foo/./bar foo/../bar foo\..\..\bar ./bar ../bar ..\..\bar"
|
||||
} else {
|
||||
r"foo/. foo/.. foo/../.. foo/./bar foo/../bar foo/../../bar ./bar ../bar ../../bar"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_command_url_args() {
|
||||
// If ndots is not handled correctly, we can lose the double forward slashes that are needed
|
||||
// here
|
||||
let actual = nu!(r#"
|
||||
nu --testbin cococo http://example.com http://example.com/.../foo //foo
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"http://example.com http://example.com/.../foo //foo"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(
|
||||
not(target_os = "linux"),
|
||||
|
Reference in New Issue
Block a user