Mercurial > hg > toybox
view tests/rm.test @ 1613:96aa7ec74936 draft
Fix yet another sed bug.
The s/// command would copy the \ of substitutions before deciding what to
do with them (generally overwriting the \ with the new data). When the
substitution was A) at the very end of the new string, B) resolved to nothing,
it could leave a trailing \ that didn't belong there and didn't get overwritten
because the "copy trailing data" part that copies the original string's null
terminator already happened before the \ overwrote it.
The ghostwheel() function restarts regexes after embedded NUL bytes, but
if the string it's passed is _longer_ than the length it's told then it
gets confused (and it means we're off the end of our allocation so segfaults
are likely).
Fix: test for \ first and move the "copy byte" logic into an else case.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 15 Dec 2014 03:34:55 -0600 |
parents | 8700cbe1cb29 |
children |
line wrap: on
line source
#!/bin/bash # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> [ -f testing.sh ] && . testing.sh #testing "name" "command" "result" "infile" "stdin" echo "abcdefghijklmnopqrstuvwxyz" > file.txt testing "Remove text-file" "rm file.txt && [ ! -e file.txt ] && echo 'yes'" "yes\n" "" "" rm -f file* mkdir dir testing "Remove empty directory" "rm -r dir && [ ! -d dir ] && echo 'yes'" "yes\n" "" "" rm -rf dir echo "abcdefghijklmnopqrstuvwxyz" > file.txt && chmod 000 file.txt testing "Remove text file(mode 000)" "rm -f file.txt && [ ! -e file.txt ] && echo 'yes'" \ "yes\n" "" "" rm -f file* touch file1.txt file2.txt mkdir dir1 dir2 testing "rm -r (multiple files and dirs)" \ "rm -r file1.txt file2.txt dir1 dir2 2>/dev/null && [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \ "yes\n" "" "" rm -rf file* dir* touch file1.txt file2.txt mkdir dir1 dir2 testing "rm -rf (present + missing files and dirs)" \ "rm -rf file1.txt file2.txt file3.txt dir1 dir2 dir3 2>/dev/null && [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \ "yes\n" "" "" rm -rf file* dir* # testing with nested dirs. mkdir -p dir1/dir2/dir3 dir1/dir2/dir4 touch dir1/file1.txt dir1/dir2/file2.txt dir1/dir2/dir3/file3.txt testing "rm -r nested_dir" "rm -r dir1/dir2/ 2>/dev/null && [ -d dir1 -a -f dir1/file1.txt -a ! -d dir1/dir2 ] && echo 'yes'" \ "yes\n" "" "" rm -rf dir*