<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 23, 2016 at 1:45 AM, Christian Boltz <span dir="ltr"><<a href="mailto:apparmor@cboltz.de" target="_blank">apparmor@cboltz.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
Am Montag, 22. Februar 2016, 01:55:35 CET schrieb Kshitij Gupta:<br>
> On Mon, Feb 22, 2016 at 1:07 AM, Kshitij Gupta wrote:<br>
<div><div class="h5">> > On Sun, Dec 27, 2015 at 8:34 PM, Christian Boltz wrote:<br>
> >> some dbus rule conditionals come with optional parenthesis. Instead<br>
> >> of making the regex even more complicated, use a small function to<br>
> >> strip those parenthesis.<br>
> >><br>
> >> Also add some tests for strip_parenthesis() to test-regex.py.<br>
> >><br>
> >><br>
> >> [ 53-add-strip_parenthesis.diff ]<br>
> >><br>
> >> === modified file ./utils/apparmor/regex.py<br>
> >> --- utils/apparmor/regex.py     2015-12-21 00:13:57.207799592 +0100<br>
> >> +++ utils/apparmor/regex.py     2015-12-24 01:19:47.916978461 +0100<br>
> >> @@ -128,6 +128,15 @@<br>
> >><br>
> >>      return matches.group('magicpath')<br>
> >><br>
> >> +def strip_parenthesis(data):<br>
> >> +    '''strips parenthesis from the given string and returns the<br>
> >> strip()ped result.<br>
> >> +       The parenthesis must be the first and last char, otherwise<br>
> >> they won't be removed.<br>
> >> +       Even if no parenthesis get removed, the result will be<br>
> >> strip()ped. +       '''<br>
> >> +    if data[0] + data[-1] == '()':<br>
> >> +        return data[1:-1].strip()<br>
> >> +    else:<br>
> >> +        return data.strip()<br>
> ><br>
> > Might be useful to do the data.strip() before the "data[0] +<br>
> > data[-1] == '()'" check, that way you don't miss on something like<br>
> > '(hey) '. This is because there doesn't seem to be a strong<br>
> > assumption that the data will already be stripped coz we return<br>
> > data.strip()<br>
<br>
</div></div>I'm following the strip_quotes() behaviour in not stripping space before<br>
removing parenthesis, and I'm quite sure the regexes that "feed"<br>
strip_parenthesis() make sure there's no whitespace around.<br>
See for example RE_ACCESS_KEYWORDS and RE_FLAG in apparmor/rule/dbus.py<br>
(from the dbus patch series, not in bzr yet)<br>
<br>
OTOH, whitespace inside parenthesis is allowed, so it makes sense to<br>
strip() it after removing the parenthesis.<br>
<span class=""><br>
> > Also, I don't see any harm in having the .strip before the check.<br>
<br>
</span>In theory it could "hide" whitespace included by (IMHO) broken regexes,<br>
with all sort of follow-up problems. I hope not-removed parenthesis (if<br>
the string starts or ends with whitespace) are more visible and easier<br>
to find, so I prefer not to strip() whe whole string.<br></blockquote><div>umm ok.<br><br>Acked-by: Kshitij Gupta <<a href="mailto:kgupta8592@gmail.com" target="_blank">kgupta8592@gmail.com</a>> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
> >>  def strip_quotes(data):<br>
> >>      if data[0] + data[-1] == '""':<br>
> >> === modified file ./utils/test/test-regex_matches.py<br>
</span>...<br>
<br>
<br>
Regards,<br>
<br>
Christian Boltz<br>
<span class=""><font color="#888888">--<br>
> Ich hätte auch nie geglaubt, das es 10 Minuten dauern kann, bis jemand<br>
> ohne Fehler einmal ein  lspci -v  fehlerfrei eingegeben hat.<br>
Hast Du auch erwähnt, daß man anschließend die RETURN-Taste drücken muß?<br>
                  [> Torsten Hallmann und Bernd Brodesser in suse-linux]<br>
</font></span><br>--<br>
AppArmor mailing list<br>
<a href="mailto:AppArmor@lists.ubuntu.com">AppArmor@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/apparmor" rel="noreferrer" target="_blank">https://lists.ubuntu.com/mailman/listinfo/apparmor</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div>Regards,<br><br></div>Kshitij Gupta<br></div></div>
</div></div>