Skip to content

Commit

Permalink
bash: Fix CR handling
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
k-takata committed Oct 2, 2024
1 parent 322a4a5 commit b8c78da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
49 changes: 18 additions & 31 deletions bash/0005-bash-4.3-msys2-fix-lineendings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ index c1135ec..b388af6 100644
*niflp = invfl;
if (vlp)
diff --git a/parse.y b/parse.y
index 0ae3458..c6e9520 100644
index 8fd24a1c..232a33dc 100644
--- a/parse.y
+++ b/parse.y
@@ -1459,7 +1459,13 @@ yy_input_name ()
Expand All @@ -99,6 +99,23 @@ index 0ae3458..c6e9520 100644
}

/* Call this to unget C. That is, to make C the next character
@@ -1684,7 +1690,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
diff --git a/shell.c b/shell.c
index ee9d445..8f25726 100644
--- a/shell.c
Expand Down Expand Up @@ -181,33 +198,3 @@ index 028667c..a10594d 100644
if (shell_variables == 0)
create_variable_tables ();

diff --git a/y.tab.c b/y.tab.c
index 32b4c7c..ac70820 100644
--- a/y.tab.c
+++ b/y.tab.c
@@ -3770,7 +3770,13 @@ yy_input_name ()
static int
yy_getc ()
{
- return (*(bash_input.getter)) ();
+#ifdef __MSYS__
+ int c;
+ while ((c = (*(bash_input.getter)) ()) == '\r');
+ return c;
+#else
+ return (*(bash_input.getter)) ();
+#endif
}

/* Call this to unget C. That is, to make C the next character
@@ -4746,6 +4752,10 @@ shell_getc (remove_quoted_newline)
else
RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);

+#ifdef __MSYS__
+ if (c == '\r')
+ continue;
+#endif
if (c == EOF)
{
if (bash_input.type == st_stream)
4 changes: 2 additions & 2 deletions bash/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pkgname=('bash' 'bash-devel')
_basever=5.2
_patchlevel=037 #prepare for some patches
pkgver=${_basever}.${_patchlevel}
pkgrel=1
pkgrel=2
pkgdesc="The GNU Bourne Again shell"
arch=('i686' 'x86_64')
license=('GPL')
Expand Down Expand Up @@ -130,7 +130,7 @@ sha256sums=('a139c166df7ff4471c5e0733051642ee5556c1cc8a4a78f145583c5c81ab32fb'
'SKIP'
'948b8b5401dcb4e5eb577cfa6543e740e2e3bd0690939d8e77d078d75d110097'
'6ca7633a87db7caf1d2d1a96779681c365d0ad2c11b2ea758e772f4ebff2a62f'
'c55c24110fbe90a2000411239e6399c1baed2843a61220b4e8a7a036f4a7436a'
'ed6a63d0e0c1d5d90e5c12405f606d2cb385f68d32181b65e0fbafd49f40f6f1'
'500c75c64593a70276585345a55c807226c0cc220d08b7cccece2ab005b3bcea'
'cbae1aa81d56eba4e916bdaf2b2983731d6e2537dd8d606a3b378e49bcb81e79'
'f42f2fee923bc2209f406a1892772121c467f44533bedfe00a176139da5d310a'
Expand Down

0 comments on commit b8c78da

Please sign in to comment.