aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-01-30 12:24:34 +0000
committerRon Yorston <rmy@pobox.com>2023-01-30 12:24:34 +0000
commitb9a1b02dee2b82e4e4a580c446a1e022aa96166d (patch)
tree6dfc496086422beffd9880d8e06ed4506d201495
parent7a537eb71874cd6c8d0e9ab1f906e6466e7f793c (diff)
downloadbusybox-w32-b9a1b02dee2b82e4e4a580c446a1e022aa96166d.tar.gz
busybox-w32-b9a1b02dee2b82e4e4a580c446a1e022aa96166d.tar.bz2
busybox-w32-b9a1b02dee2b82e4e4a580c446a1e022aa96166d.zip
ash,make: fix CRLF handling
Fix remove_cr() so it only removes CRs which are part of a CRLF pair, not every CR. Add a test case for the shell.
-rwxr-xr-xtestsuite/sh.tests6
-rw-r--r--win32/mingw.c5
2 files changed, 9 insertions, 2 deletions
diff --git a/testsuite/sh.tests b/testsuite/sh.tests
index 2a510fb25..872611a1b 100755
--- a/testsuite/sh.tests
+++ b/testsuite/sh.tests
@@ -88,3 +88,9 @@ IyEvYmluL3NoICAtIAplY2hvICJIZWxsbyB3b3JsZCIK
88==== 88====
89" 89"
90rm -f shebang_leading_argument_trailing_space.sh 90rm -f shebang_leading_argument_trailing_space.sh
91
92testing "remove CRs from string being evaluated" \
93 "sh -c \"$(printf 'set -e\r\necho Hello world\r\n')\"" \
94 "Hello world\n" "" ""
95
96exit $FAILCOUNT
diff --git a/win32/mingw.c b/win32/mingw.c
index 5cd7e74db..4d07a24e5 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2030,8 +2030,9 @@ size_t FAST_FUNC remove_cr(char *p, size_t len)
2030 ssize_t i, j; 2030 ssize_t i, j;
2031 2031
2032 for (i=j=0; i<len; ++i) { 2032 for (i=j=0; i<len; ++i) {
2033 if (p[i] != '\r') 2033 if (p[i] == '\r' && i < len - 1 && p[i+1] == '\n')
2034 p[j++] = p[i]; 2034 continue;
2035 p[j++] = p[i];
2035 } 2036 }
2036 return j; 2037 return j;
2037} 2038}