Skip to content

Commit e9e495b

Browse files
authored
Merge pull request #105 from vadimb892/sed-fix
READY: [sed] fix
2 parents 1340d1b + 50bb365 commit e9e495b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

text/sed.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,11 @@ fn execute_replace(
18341834
}) {
18351835
if replace && wfile.components().next().is_some() {
18361836
let mut wfile = wfile.clone();
1837-
if (cfg!(test) || cfg!(debug_assertions)) && !wfile.exists() {
1837+
if !(wfile.is_absolute()
1838+
|| wfile.starts_with("./")
1839+
|| wfile.starts_with("../")
1840+
|| wfile.exists())
1841+
{
18381842
wfile = get_tmp_path(wfile);
18391843
}
18401844

@@ -2231,7 +2235,11 @@ impl Sed {
22312235

22322236
fn execute_w(&mut self, wfile: PathBuf) -> Result<(), SedError> {
22332237
let mut wfile = wfile.clone();
2234-
if (cfg!(test) || cfg!(debug_assertions)) && !wfile.exists() {
2238+
if !(wfile.is_absolute()
2239+
|| wfile.starts_with("./")
2240+
|| wfile.starts_with("../")
2241+
|| wfile.exists())
2242+
{
22352243
wfile = get_tmp_path(wfile);
22362244
}
22372245

text/tests/sed/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,17 +1825,16 @@ mod tests {
18251825
fn test_w() {
18261826
let test_data = [
18271827
// correct
1828-
("w ./newfile", "abc\ncdf\n", "abc\ncdf\n", ""),
18291828
("w atyfv", "abc\ncdf\n", "abc\ncdf\n", ""),
18301829
("w./tests/sed/assets/r", "", "", ""),
1831-
("w./newfile", "a\n", "a\n", ""),
1830+
("w newfile", "a\n", "a\n", ""),
18321831
("w ; h", "abc\ncdf\n", "abc\ncdf\n", ""),
18331832
// wrong
18341833
(
18351834
"w ./dir/newfile",
18361835
"abc\ncdf\n",
18371836
"",
1838-
"sed: read stdin: can't find '../target/tmp/./dir/newfile': no such file or directory (os error 2)\n",
1837+
"sed: read stdin: can't find './dir/newfile': no such file or directory (os error 2)\n",
18391838
),
18401839
(
18411840
"w./tests/s\x04ed/assets/abc",

0 commit comments

Comments
 (0)