-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bash: Fix CR handling #4477
base: master
Are you sure you want to change the base?
bash: Fix CR handling #4477
Conversation
Sorry for the delay. I'll try to find some time/motivation for a more in-depth look. Do you see any potential problems with the default changing for existing users? |
In this PR, the most important part is here: diff --git a/parse.y b/parse.y
index 8fd24a1c..232a33dc 100644
@@ -1678,7 +1684,16 @@ rewind_input_string ()
into account, e.g., $(...\n) */
xchars = shell_input_line_len - shell_input_line_index;
if (bash_input.location.string[-1] == '\n')
- xchars++;
+ {
+ xchars++;
+#ifdef __CYGWIN__
+ {
+ extern int igncr;
+ if (igncr && bash_input.location.string[-2] == '\r')
+ xchars++;
+ }
+#endif
+ }
/* XXX - how to reflect bash_input.location.string back to string passed to
parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how If you have concerning about changing diff --git a/parse.y b/parse.y
index 8fd24a1c..232a33dc 100644
@@ -1678,7 +1684,15 @@ rewind_input_string ()
into account, e.g., $(...\n) */
xchars = shell_input_line_len - shell_input_line_index;
if (bash_input.location.string[-1] == '\n')
- xchars++;
+ {
+ xchars++;
+#ifdef __MSYS__
+ {
+ if (bash_input.location.string[-2] == '\r')
+ xchars++;
+ }
+#endif
+ }
/* XXX - how to reflect bash_input.location.string back to string passed to
parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how (Some other hunks need to be reverted in this case.) |
I gave it another try. One thing test3() {
local input="Line with\r Carriage Return"
local expected="Line with Carriage Return"
local result=$(echo -e "$input")
[ "$result" != "$expected" ] && echo "OK" || echo "FAILED"
}
test3 that feels a bit risky, so I'd prefer the non-igncr variant, for now at least. I'll try to write some tests covering the changes we currently have compared to upstream. Do you also have some example code that tests your changes, so we can add it to our integration tests? After that we can think about enabling igncr again. |
Don't use the igncr option for now as suggested at msys2#4477.
OK, I've updated the PR not to use igncr.
Unfortunately, I have no ideas how to test the PS1 issue. Another test that might be better to add is to test a script file with CRLF line endings. |
(Sorry, closed by mistake. Reopened.) |
We received another report in oh-my-bash caused by this issue. May I ask what is the current blocker of this fix? Is it blocked because no one knows how to test the change? What is the current progress for the tests? |
Fixes msys2#1839 `0005-bash-4.3-msys2-fix-lineendings.patch` adds CRLF support. However, `0001-bash-4.4-cygwin.patch` already added `igncr` option to Bash to support CRLF. I confirmed that the Cygwin version of Bash has also the same issue with msys2#1839 when the `igncr` option is set. After debugging, I found that there is an issue in `rewind_input_string()` in `parser.y` that it doesn't take the CR into account. This PR adds the following changes: * Modify `rewind_input_string()` to take the CR into account. (It might be better to apply a similar change to the Cygwin version of Bash.) * Remove all the changes from `y.tab.c`. This file should be automatically generated from `parser.y`.
319f0f4
to
86781a3
Compare
Added a test named
On the patched version, only the test name is shown:
|
`check()` failed on non-English locales. Set LC_ALL to C.UTF-8.
Add `run-ps1lf`.
86781a3
to
92d725c
Compare
Note: This patch contains a line with CRLF. So, .gitattributes is also updated to keep the CRLF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run-crlf
is added to test CRLF handling in $(...)
.
+Line with CR | ||
+Line with CRLF | ||
+Line with | ||
+ LF | ||
+Line with CR | ||
+Line with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 183, 184, and 187 contain CR, and line 188 ends with CRLF.
bash/.gitattributes
has been added to keep the CRs.
Fixes #1839
0005-bash-4.3-msys2-fix-lineendings.patch
adds CRLF support. However,0001-bash-4.4-cygwin.patch
already addedigncr
option to Bash to support CRLF.I confirmed that the Cygwin version of Bash has also the same issue with #1839 when the
igncr
option is set.After debugging, I found that there is an issue in
rewind_input_string()
inparser.y
that it doesn't take the CR into account.This PR adds the following changes:
Set theigncr
option by default.Remove unnecessary changes inyy_input_name()
inparser.y
and use theigncr
implementation.rewind_input_string()
to take the CR into account. (It might be better to apply a similar change to the Cygwin version of Bash.)y.tab.c
. This file should be automatically generated fromparser.y
.LC_ALL=C.UTF-8
when runningmake check
for running on non-English locales.run-ps1lf
.