[augeas-devel] [PATCH 6/6] Don't require backslashes to be escaped in regexps
Raphaël Pinson
raphink at gmail.com
Mon Oct 10 09:03:57 UTC 2011
2011/10/10 Raphaël Pinson <raphink at gmail.com>
> This patch actually breaks a lot of things. Quite a few unit tests don't
> pass after it is applied.
>
> It might be OK to remove the backslashes inside character sets, but not
> outside I think.
>
>
Got it, you have to rebuild Augeas with patch 5 applied. Sorry for my
misunderstanding. I will let David review patches 5 and 6.
Raphaël
On Sat, Oct 8, 2011 at 1:08 PM, Michael Chapman <mike at very.puzzling.org>wrote:
> This patch removes \\ from the list of escapes used when handling
> regexps.
>
> The effect is that where previously we had to use:
>
> /\\\\./
>
> to mean "backslash followed by any character", now the more logical:
>
> /\\./
>
> must be used.
>
> Signed-off-by: Michael Chapman <mike at very.puzzling.org>
> ---
> lenses/dhcpd.aug | 2 +-
> lenses/httpd.aug | 10 +++++-----
> lenses/interfaces.aug | 2 +-
> lenses/iptables.aug | 2 +-
> lenses/modprobe.aug | 6 +++---
> lenses/shellvars.aug | 4 ++--
> lenses/shellvars_list.aug | 4 ++--
> lenses/sudoers.aug | 8 ++++----
> lenses/sysconfig.aug | 2 +-
> lenses/syslog.aug | 4 ++--
> lenses/wine.aug | 10 +++++-----
> src/internal.h | 2 +-
> tests/modules/pass_cont_line.aug | 2 +-
> 13 files changed, 29 insertions(+), 29 deletions(-)
>
> diff --git a/lenses/dhcpd.aug b/lenses/dhcpd.aug
> index 8cbc3db..a6bff16 100644
> --- a/lenses/dhcpd.aug
> +++ b/lenses/dhcpd.aug
> @@ -81,7 +81,7 @@ let ip = Rx.ipv4
>
> (* borrowed from sysconfig.aug *)
> (* Chars allowed in a bare string *)
> - let bchar = /[^ \t\n"'\\{}#,()]|\\\\./
> + let bchar = /[^ \t\n"'\\{}#,()]|\\./
> let qchar = /["']/ (* " *)
>
> (* We split the handling of right hand sides into a few cases:
> diff --git a/lenses/httpd.aug b/lenses/httpd.aug
> index 958324f..3389798 100644
> --- a/lenses/httpd.aug
> +++ b/lenses/httpd.aug
> @@ -45,7 +45,7 @@ autoload xfm
> let dels (s:string) = del s s
>
> (* deal with continuation lines *)
> -let sep_spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
> +let sep_spc = del /([ \t]+|[ \t]*\\\n[ \t]*)/ " "
>
> let sep_osp = Sep.opt_space
> let sep_eq = del /[ \t]*=[ \t]*/ "="
> @@ -59,10 +59,10 @@ let empty = Util.empty
> let indent = Util.indent
>
> (* borrowed from shellvars.aug *)
> -let char_arg_dir = /[^ '"\t\n]|\\\\"|\\\\'/
> -let char_arg_sec = /[^ '"\t\n>]|\\\\"|\\\\'/
> -let dquot = /"([^"\\\n]|\\\\.)*"/
> -let squot = /'([^'\\\n]|\\\\.)*'/
> +let char_arg_dir = /[^ '"\t\n]|\\"|\\'/
> +let char_arg_sec = /[^ '"\t\n>]|\\"|\\'/
> +let dquot = /"([^"\\\n]|\\.)*"/
> +let squot = /'([^'\\\n]|\\.)*'/
>
> (******************************************************************
> * Attributes
> diff --git a/lenses/interfaces.aug b/lenses/interfaces.aug
> index 4dc280f..66c2da0 100644
> --- a/lenses/interfaces.aug
> +++ b/lenses/interfaces.aug
> @@ -18,7 +18,7 @@ let eol = Util.eol
>
> (* a line can be extended across multiple lines by making the last *)
> (* character a backslash *)
> -let sep_spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
> +let sep_spc = del /([ \t]+|[ \t]*\\\n[ \t]*)/ " "
>
> (* Define fields *)
> let sto_to_eol = store /([^\\ \t\n].*[^\\ \t\n]|[^\\ \t\n])/ . eol
> diff --git a/lenses/iptables.aug b/lenses/iptables.aug
> index 28e6bfe..f794091 100644
> --- a/lenses/iptables.aug
> +++ b/lenses/iptables.aug
> @@ -51,7 +51,7 @@ let tcp_flags =
> let ipt_match =
> let any_key = /[a-zA-Z-][a-zA-Z-]+/ -
>
> /protocol|source|destination|jump|goto|in-interface|out-interface|fragment|match|tcp-flags/
> in
> - let any_val = /([^" \t\n!-][^ \t\n]*)|"([^"\\\n]|\\\\.)*"/ in
> + let any_val = /([^" \t\n!-][^ \t\n]*)|"([^"\\\n]|\\.)*"/ in
> let any_param =
> [ [ spc . dels "!" . label "not" ]? .
> spc . dels "--" . key any_key . (spc . store any_val)? ] in
> diff --git a/lenses/modprobe.aug b/lenses/modprobe.aug
> index bdecafb..5f5be89 100644
> --- a/lenses/modprobe.aug
> +++ b/lenses/modprobe.aug
> @@ -16,9 +16,9 @@ let eol = Util.eol | Util.comment
> *)
>
> (* A separator is either whitespace or \ followed by newline *)
> -let sep_ch = /[ \t]|\\\\\n/
> +let sep_ch = /[ \t]|\\\n/
> (* Anything that's not a separator is part of a token *)
> -let tok_ch = /[^ \t\n#\\]|\\\\[^ \t\n]/
> +let tok_ch = /[^ \t\n#\\]|\\[^ \t\n]/
>
> let spc = del sep_ch+ " "
> let token = store tok_ch+
> @@ -26,7 +26,7 @@ let indent = Util.del_opt_ws ""
>
> let cmd (n:regexp) = key n . spc
> let arg (n:string) = [ label n . token ]
> -let token_to_eol = store (tok_ch . /([^#\n\\]|\\\\\n)*/ . tok_ch | tok_ch)
> +let token_to_eol = store (tok_ch . /([^#\n\\]|\\\n)*/ . tok_ch | tok_ch)
>
> let options =
> let opt_ch = /[A-Za-z0-9_]/ in
> diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
> index d419a4b..9c9173d 100644
> --- a/lenses/shellvars.aug
> +++ b/lenses/shellvars.aug
> @@ -13,8 +13,8 @@ module Shellvars =
> let xchgs = Build.xchgs
> let semicol = del /;?/ ""
>
> - let char = /[^;#() '"\t\n]|\\\\"/
> - let dquot = /"([^"\\\n]|\\\\.)*"/ (* " Emacs, relax
> *)
> + let char = /[^;#() '"\t\n]|\\"/
> + let dquot = /"([^"\\\n]|\\.)*"/ (* " Emacs, relax *)
> let squot = /'[^'\n]*'/
> (* For some reason, `` conflicts with comment_or_eol *)
> let bquot = /`[^#`\n]*`/
> diff --git a/lenses/shellvars_list.aug b/lenses/shellvars_list.aug
> index 7f5fa2c..f585853 100644
> --- a/lenses/shellvars_list.aug
> +++ b/lenses/shellvars_list.aug
> @@ -13,8 +13,8 @@ module Shellvars_list =
> let indent = Util.indent
>
> let sqword = /[^ '\t\n]+/
> - let dqword = /([^ "\\\t\n]|\\\\.)+/
> - let uqword = /([^ "'\\\t\n]|\\\\.)+/
> + let dqword = /([^ "\\\t\n]|\\.)+/
> + let uqword = /([^ "'\\\t\n]|\\.)+/
>
> (* lists values of the form ... val1 val2 val3 ... *)
> let list(word:regexp) =
> diff --git a/lenses/sudoers.aug b/lenses/sudoers.aug
> index 376e590..dea0b3e 100644
> --- a/lenses/sudoers.aug
> +++ b/lenses/sudoers.aug
> @@ -61,10 +61,10 @@ let indent = del /[ \t]*/ ""
> let sep_spc = del /[ \t]+/ " "
>
> (* Variable: sep_cont *)
> -let sep_cont = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
> +let sep_cont = del /([ \t]+|[ \t]*\\\n[ \t]*)/ " "
>
> (* Variable: sep_cont_opt *)
> -let sep_cont_opt = del /([ \t]*|[ \t]*\\\\\n[ \t]*)/ " "
> +let sep_cont_opt = del /([ \t]*|[ \t]*\\\n[ \t]*)/ " "
>
> (* Variable: sep_com *)
> let sep_com = sep_cont_opt . Util.del_str "," . sep_cont_opt
> @@ -83,7 +83,7 @@ let sep_dquote = Util.del_str "\""
>
> (* Variable: sto_to_com_cmnd
> sto_to_com_cmnd does not begin or end with a space *)
> -let sto_to_com_cmnd = store /([^,=:#()
> \t\n\\]([^,=:#()\n\\]|\\\\[=:,\\])*[^,=:#() \t\n\\])|[^,=:#() \t\n\\]/
> +let sto_to_com_cmnd = store /([^,=:#()
> \t\n\\]([^,=:#()\n\\]|\\[=:,\\])*[^,=:#() \t\n\\])|[^,=:#() \t\n\\]/
>
> (* Variable: sto_to_com
>
> @@ -96,7 +96,7 @@ let sto_to_com_host = store /[^,=:#() \t\n\\]+/
>
> (* Variable: sto_to_com_user
> Escaped spaces are allowed *)
> -let sto_to_com_user = store ( /([^,=:#() \t\n]([^,=:#() \t\n]|(\\\\[
> \t]))*[^,=:#() \t\n])|[^,=:#() \t\n]/
> +let sto_to_com_user = store ( /([^,=:#() \t\n]([^,=:#() \t\n]|(\\[
> \t]))*[^,=:#() \t\n])|[^,=:#() \t\n]/
> - /(User|Runas|Host|Cmnd)_Alias|Defaults.*/ )
>
> (* Variable: sto_to_com_col *)
> diff --git a/lenses/sysconfig.aug b/lenses/sysconfig.aug
> index 2c7efaa..b1b7517 100644
> --- a/lenses/sysconfig.aug
> +++ b/lenses/sysconfig.aug
> @@ -16,7 +16,7 @@ module Sysconfig =
> let nothing = del /(""|'')?/ "" . value ""
>
> (* Chars allowed in a bare string *)
> - let bchar = /[^ \t\n"'\\]|\\\\./
> + let bchar = /[^ \t\n"'\\]|\\./
> let qchar = /["']/ (* " *)
>
> (* We split the handling of right hand sides into a few cases:
> diff --git a/lenses/syslog.aug b/lenses/syslog.aug
> index cda17bb..fe5df3e 100644
> --- a/lenses/syslog.aug
> +++ b/lenses/syslog.aug
> @@ -33,10 +33,10 @@ module Syslog =
> (* Variable: eol *)
> let eol = Util.eol
> (* Variable: sep_tab *)
> - let sep_tab = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ "\t"
> + let sep_tab = del /([ \t]+|[ \t]*\\\n[ \t]*)/ "\t"
>
> (* Variable: sep_tab_opt *)
> - let sep_tab_opt = del /([ \t]*|[ \t]*\\\\\n[ \t]*)/ ""
> + let sep_tab_opt = del /([ \t]*|[ \t]*\\\n[ \t]*)/ ""
>
> (* View: comment
> Map comments into "#comment" nodes
> diff --git a/lenses/wine.aug b/lenses/wine.aug
> index bd43a17..21a68f8 100644
> --- a/lenses/wine.aug
> +++ b/lenses/wine.aug
> @@ -21,13 +21,13 @@ let header =
> [ label "version" . store /[0-9.]+/ ] . eol
>
> let qstr =
> - let re = /([^"\n]|\\\\.)*/ - /@|"@"/ in (* " Relax, emacs *)
> + let re = /([^"\n]|\\.)*/ - /@|"@"/ in (* " Relax, emacs *)
> dels "\"" . store re . dels "\""
>
> let typed_val =
> - ([ label "type" . store /dword|hex(\\([0-9]+\\))?/ ] . dels ":" .
> - [ label "value" . store /[a-zA-Z0-9,()]+(\\\\\r?\n[
> \t]*[a-zA-Z0-9,]+)*/])
> - |([ label "type" . store /str\\([0-9]+\\)/ ] . dels ":" .
> + ([ label "type" . store /dword|hex(\([0-9]+\))?/ ] . dels ":" .
> + [ label "value" . store /[a-zA-Z0-9,()]+(\\\r?\n[
> \t]*[a-zA-Z0-9,]+)*/])
> + |([ label "type" . store /str\([0-9]+\)/ ] . dels ":" .
> dels "\"" . [ label "value" . store /[^"\n]*/ ] . dels "\"") (* "
> Relax, emacs *)
>
> let entry =
> @@ -39,7 +39,7 @@ let entry =
>
> let section =
> let ts = [ label "timestamp" . store Rx.integer ] in
> - [ label "section" . del /[ \t]*\\[/ "[" .
> + [ label "section" . del /[ \t]*\[/ "[" .
> store /[^]\n]+/ . dels "]" . (del_ws . ts)? . eol .
> (entry|empty|comment)* ]
>
> diff --git a/src/internal.h b/src/internal.h
> index 8c58d37..9cc38ac 100644
> --- a/src/internal.h
> +++ b/src/internal.h
> @@ -260,7 +260,7 @@ char *unescape(const char *s, int len, const char
> *extra);
>
> /* Extra characters to be escaped in strings and regexps respectively */
> #define STR_ESCAPES "\"\\"
> -#define RX_ESCAPES "/\\"
> +#define RX_ESCAPES "/"
>
> /* Function: print_chars */
> int print_chars(FILE *out, const char *text, int cnt);
> diff --git a/tests/modules/pass_cont_line.aug
> b/tests/modules/pass_cont_line.aug
> index a914cc9..9633c09 100644
> --- a/tests/modules/pass_cont_line.aug
> +++ b/tests/modules/pass_cont_line.aug
> @@ -5,7 +5,7 @@ module Pass_cont_line =
>
> let list_elt = [ label "element" . store /[a-z]+/ ]
>
> -let ws_cont = /([ \t]+|[ \t]*\\\\\n[ \t]*)/
> +let ws_cont = /([ \t]+|[ \t]*\\\n[ \t]*)/
>
> let sep = del ws_cont " "
> let eol = del /[ \t]*\n/ "\n"
> --
> 1.7.6.4
>
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20111010/d1cd225a/attachment.htm>
More information about the augeas-devel
mailing list