Skip to content

Commit d2f6996

Browse files
authored
Merge pull request #9129 from mattsu2020/truncate_fix
feat(truncate): allow negative size values for truncation
2 parents 8f62357 + 7ca5f66 commit d2f6996

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/uu/truncate/src/truncate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub fn uu_app() -> Command {
145145
.long(options::SIZE)
146146
.required_unless_present(options::REFERENCE)
147147
.help(translate!("truncate-help-size"))
148+
.allow_hyphen_values(true)
148149
.value_name("SIZE"),
149150
)
150151
.arg(

tests/by-util/test_truncate.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,17 @@ fn test_underflow_relative_size() {
386386
assert!(at.read_bytes(FILE1).is_empty());
387387
}
388388

389+
#[test]
390+
fn test_negative_size_with_space() {
391+
let (at, mut ucmd) = at_and_ucmd!();
392+
ucmd.args(&["-s", "-1", FILE1])
393+
.succeeds()
394+
.no_stdout()
395+
.no_stderr();
396+
assert!(at.file_exists(FILE1));
397+
assert!(at.read_bytes(FILE1).is_empty());
398+
}
399+
389400
#[cfg(not(windows))]
390401
#[test]
391402
fn test_fifo_error_size_only() {

0 commit comments

Comments
 (0)