[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] regex: Add extra escapes to regular expressions in m4
From: |
Eric Blake |
Subject: |
Re: [PATCH] regex: Add extra escapes to regular expressions in m4 |
Date: |
Tue, 29 Jan 2019 20:44:36 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 1/29/19 8:23 PM, Siddhesh Poyarekar wrote:
> On 30/01/19 2:16 AM, Eric Blake wrote:
>> Looking at m4/fnmatch.m4, it looks like we are already used to the idea
>> of doubling up \\ that will pass through AC_LANG_PROGRAM() and the
>> unquoted heredoc; on that grounds, your patch is correct.
>
> Sorry yes, it's the shell that's eating up the backslashes; I basically
> compared the generated conftest.c and tests/test-regex.c to check if
> both programs had the same regex and they didn't. Is it OK to commit
> this oatchpatch or would you like me to make any additional changes
> beyond changing the commit message?
A few more comments never hurt. Here's what I'll push tomorrow to
gnulib, if there are no further objections (a doc patch to autoconf is
also needed, but that will be a different reply):
From 108415713702c22a3eee10c22624c916948129bf Mon Sep 17 00:00:00 2001
From: Siddhesh Poyarekar <address@hidden>
Date: Tue, 29 Jan 2019 20:40:09 -0600
Subject: [PATCH] regex: Account for heredoc eating doubled \.
AC_LANG_PROGRAM and friends create testconf.c by using an
unquoted heredoc - but this eats any doubled \. Match what
is done in fnmatch.m4 by adding extra \ for backslashes
which must survived doubled into the resulting .c test file.
* m4/regex.m4 (gl_REGEX): Add extra escape characters to
regular expressions.
---
ChangeLog | 6 ++++++
m4/regex.m4 | 12 ++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 184908905..f28abb7d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-29 Siddhesh Poyarekar <address@hidden>
+
+ regex: Account for heredoc eating doubled \.
+ * m4/regex.m4 (gl_REGEX): Add extra escape characters to
+ regular expressions.
+
2019-01-06 Bruno Haible <address@hidden>
maintainer-makefile: Make the configure.ac section optional.
diff --git a/m4/regex.m4 b/m4/regex.m4
index 35119c5c8..24c04667e 100644
--- a/m4/regex.m4
+++ b/m4/regex.m4
@@ -1,4 +1,4 @@
-# serial 68
+# serial 69
# Copyright (C) 1996-2001, 2003-2019 Free Software Foundation, Inc.
#
@@ -204,7 +204,11 @@ AC_DEFUN([gl_REGEX],
& ~RE_CONTEXT_INVALID_DUP
& ~RE_NO_EMPTY_RANGES);
memset (®ex, 0, sizeof regex);
- s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex);
+
+ /* #AC_LANG_PROGRAM uses shell heredoc, which requires
+ doubled \; we want to apply + operator to match 1-or-more
+ backslash, which requires 4 \ in a C string or 8 here */
+ s = re_compile_pattern ("[[:alnum:]_-]\\\\\\\\+$", 16, ®ex);
if (s)
result |= 32;
@@ -217,10 +221,10 @@ AC_DEFUN([gl_REGEX],
an assertion failure prior to glibc-2.28:
regexec.c:1375: pop_fail_stack: Assertion 'num >= 0'
failed
With glibc-2.28, compilation fails and reports the invalid
- back reference. */
+ back reference. See above comment about doubled \. */
re_set_syntax (RE_SYNTAX_POSIX_EGREP);
memset (®ex, 0, sizeof regex);
- s = re_compile_pattern ("0|()0|\\1|0", 10, ®ex);
+ s = re_compile_pattern ("0|()0|\\\\1|0", 10, ®ex);
if (!s || strcmp (s, "Invalid back reference"))
result |= 64;
--
2.20.1
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature