[augeas-devel] [PATCH 5/6] Fix regular expression escaping

David Lutterkort lutter at redhat.com
Mon Oct 17 16:39:23 UTC 2011


On Sat, 2011-10-08 at 22:08 +1100, Michael Chapman wrote:
> This patch fixes:
> 
>   /[\/]/
> 
> Previously, this matched either a backslash or a slash, since \/ was not
> an escape sequence known to unescape(). Now this matches only a slash.
> 
> We pass an extra argument to escape() and unescape() listing the extra
> characters that should be handled. STR_ESCAPES and RX_ESCAPES provide
> the extra characters for strings and regexps respectively, and NULL may
> be passed if no extra characters should be handled.
> 
> Signed-off-by: Michael Chapman <mike at very.puzzling.org>

ACK. Pushed as e3dd00ff with one minor change:

> diff --git a/src/internal.c b/src/internal.c
> index 9f4b697..6ce24dd 100644
> --- a/src/internal.c
> +++ b/src/internal.c
> @@ -162,7 +162,9 @@ char *unescape(const char *s, int len) {
>  
>      size = 0;
>      for (i=0; i < len; i++, size++)
> -        if (s[i] == '\\' && strchr(escape_names, s[i+1]) != NULL) {
> +        if (s[i] == '\\' && (n = strchr(escape_names, s[i+1])) != NULL) {
> +            i += 1;
> +        } else if (s[i] == '\\' && extra && strchr(extra, s[i+1]) != NULL) {
>              i += 1;
>          }

Got rid of the unused assignment to n and enclosed the whole for body in
'{ ... }'.

David





More information about the augeas-devel mailing list