sed: support \r in s command
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 2 May 2011 22:52:22 +0000 (00:52 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 2 May 2011 22:52:22 +0000 (00:52 +0200)
function                                             old     new   delta
copy_parsing_escapes                                  65      91     +26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c
testsuite/sed.tests

index 9e27e3e1857b8fc88630dec212751a7e4c1ca777..11c4763213a2192a8f06c565bddf5a30929dc71a 100644 (file)
@@ -218,8 +218,9 @@ static char *copy_parsing_escapes(const char *string, int len)
        char *dest = xmalloc(len + 1);
 
        parse_escapes(dest, string, len, 'n', '\n');
-       /* GNU sed also recognizes \t */
+       /* GNU sed also recognizes \t and \r */
        parse_escapes(dest, dest, strlen(dest), 't', '\t');
+       parse_escapes(dest, dest, strlen(dest), 'r', '\r');
        return dest;
 }
 
index 395372ae685b1696b9a6bd09335bb245e24ce0a6..e9d0ed6018ee32ddfc32883ce4cae8a3f21ec87d 100755 (executable)
@@ -287,6 +287,9 @@ testing "sed -i with address modifies all files, not only first" \
        "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \
        "bar\nbar\n" "foo\n" ""
 
+testing "sed understands \r" \
+       "sed 's/r/\r/'" \
+       "\rrr\n" "" "rrr\n"
 
 # testing "description" "arguments" "result" "infile" "stdin"