2022-02-02 20:59:01 +00:00
|
|
|
use nu_path::expand_path_with;
|
2023-04-08 18:52:37 +00:00
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::path::PathBuf;
|
2022-02-02 20:59:01 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
2021-09-15 19:11:28 +00:00
|
|
|
#[test]
|
|
|
|
fn expand_path_with_and_without_relative() {
|
|
|
|
let relative_to = "/foo/bar";
|
|
|
|
let path = "../..";
|
|
|
|
let full_path = "/foo/bar/../..";
|
|
|
|
|
2022-02-02 20:59:01 +00:00
|
|
|
let cwd = std::env::current_dir().expect("Could not get current directory");
|
|
|
|
assert_eq!(
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
expand_path_with(full_path, cwd, true),
|
|
|
|
expand_path_with(path, relative_to, true),
|
2022-02-02 20:59:01 +00:00
|
|
|
);
|
2021-09-15 19:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_relative() {
|
|
|
|
let relative_to = "/foo/bar";
|
|
|
|
let path = "../..";
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
assert_eq!(
|
|
|
|
PathBuf::from("/"),
|
|
|
|
expand_path_with(path, relative_to, true),
|
|
|
|
);
|
2021-09-15 19:11:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 20:59:01 +00:00
|
|
|
#[cfg(not(windows))]
|
2021-09-15 19:11:28 +00:00
|
|
|
#[test]
|
|
|
|
fn expand_path_no_change() {
|
|
|
|
let path = "/foo/bar";
|
|
|
|
|
2022-02-02 20:59:01 +00:00
|
|
|
let cwd = std::env::current_dir().expect("Could not get current directory");
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(path, cwd, true);
|
2021-09-15 19:11:28 +00:00
|
|
|
|
|
|
|
assert_eq!(actual, PathBuf::from(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_unicode_path_no_change() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut spam = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
spam.push("🚒.txt");
|
|
|
|
|
2022-02-02 20:59:01 +00:00
|
|
|
let cwd = std::env::current_dir().expect("Could not get current directory");
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(spam, cwd, true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("🚒.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ignore]
|
|
|
|
#[test]
|
|
|
|
fn expand_non_utf8_path() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_unicode_path_relative_to_unicode_path_with_spaces() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut relative_to = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
relative_to.push("e-$ èрт🚒♞中片-j");
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("🚒.txt", relative_to, true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("e-$ èрт🚒♞中片-j/🚒.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ignore]
|
|
|
|
#[test]
|
|
|
|
fn expand_non_utf8_path_relative_to_non_utf8_path_with_spaces() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_absolute_path_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut absolute_path = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
absolute_path.push("spam.txt");
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(&absolute_path, "non/existent/directory", true);
|
2021-09-15 19:11:28 +00:00
|
|
|
let expected = absolute_path;
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_dot_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("./spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_many_dots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("././/.//////./././//.////spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_double_dot_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("foo/../spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_many_double_dots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("foo/bar/baz/../../../spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_3_ndots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("foo/bar/.../spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_many_3_ndots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
|
|
|
let actual = expand_path_with(
|
|
|
|
"foo/bar/baz/eggs/sausage/bacon/.../.../.../spam.txt",
|
|
|
|
dirs.test(),
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
true,
|
2021-09-15 19:11:28 +00:00
|
|
|
);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_4_ndots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("foo/bar/baz/..../spam.txt", dirs.test(), true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_many_4_ndots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
|
|
|
let actual = expand_path_with(
|
|
|
|
"foo/bar/baz/eggs/sausage/bacon/..../..../spam.txt",
|
|
|
|
dirs.test(),
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
true,
|
2021-09-15 19:11:28 +00:00
|
|
|
);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_with_way_too_many_dots_relative_to() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut relative_to = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
relative_to.push("foo/bar/baz/eggs/sausage/bacon/vikings");
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(
|
|
|
|
"././..////././...///././.....///spam.txt",
|
|
|
|
relative_to,
|
|
|
|
true,
|
|
|
|
);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("spam.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_unicode_path_with_way_too_many_dots_relative_to_unicode_path_with_spaces() {
|
|
|
|
Playground::setup("nu_path_test_1", |dirs, _| {
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut relative_to = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
relative_to.push("foo/áčěéí +šř=é/baz/eggs/e-$ èрт🚒♞中片-j/bacon/öäöä öäöä");
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with("././..////././...///././.....///🚒.txt", relative_to, true);
|
2023-09-12 06:06:56 +00:00
|
|
|
let mut expected = dirs.test().to_owned();
|
2021-09-15 19:11:28 +00:00
|
|
|
expected.push("🚒.txt");
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_tilde() {
|
|
|
|
let tilde_path = "~";
|
|
|
|
|
2022-02-02 20:59:01 +00:00
|
|
|
let cwd = std::env::current_dir().expect("Could not get current directory");
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(tilde_path, cwd, true);
|
2021-09-15 19:11:28 +00:00
|
|
|
|
|
|
|
assert!(actual.is_absolute());
|
|
|
|
assert!(!actual.starts_with("~"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn expand_path_tilde_relative_to() {
|
|
|
|
let tilde_path = "~";
|
|
|
|
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 02:08:38 +00:00
|
|
|
let actual = expand_path_with(tilde_path, "non/existent/path", true);
|
2021-09-15 19:11:28 +00:00
|
|
|
|
|
|
|
assert!(actual.is_absolute());
|
|
|
|
assert!(!actual.starts_with("~"));
|
|
|
|
}
|