Menu

#2 in :regex matching \\ is the escape

None
open
Parser (5)
2012-11-14
2008-10-22
No

While on the validating page this line went through as valid:
[...]
if header :regex "eCentrum-Score_Stars" "^\*{2,5}") {
[...]

it won't work with eg. dovecot's sieve implementation, because the draft[1] says the escape character must be \\, and AFAIK you can not pass the \ as an operand to the * repetition operator.

So the correct (and working) line is:
if header :regex "eCentrum-Score_Stars" "^\\*{2,5}") {

Daniel

Discussion

  • Heiko Hund

    Heiko Hund - 2008-11-09

    Thanks for the report.

    What are the symptoms if you use the wrong regex with dovecot? I'm asking because the Sieve RFC is pretty clear that it is no error to prepend a '\' to any character. From 2.4.2:

    An undefined escape sequence (such as "\a" in a context where "a" has no special meaning) is interpreted as if there were no backslash (in this case, "\a" is just "a"), though that may be changed by extensions.

    For you that probably means that currently '\*' translates to '*' (which gives a invalid regex). As far as I can tell it could also be interpreted correctly because '\*' does have special meaning in this context and needs not to be changed in principle. Have you talked to Stephan Bosch about this? I would like to hear his opinion on this issue.

     
  • Lévai Dániel

    Lévai Dániel - 2008-11-10

    When using the wrong regex, during the sieve script compilation, it outputs this:
    $ /usr/local/libexec/dovecot/sievec .dovecot.sieve .dovecot.sievec
    Info: line 16: repetition-operator operand invalid

    Unable to parse script: script errors:
    line 16: repetition-operator operand invalid

    Stephan Bosch is the maintainer of managesieve, but I am not using that. I'm experiencing this issue with dovecot's sieve plugin, which is maintined by Timo Sirainen along with the whole dovecot server.

    I think the plugin thinks that '\' is and operand to '*' operator, and if I want to escape '*', I must use the escape sequence '\\'. One could wonder however, what if I wanted to write a regex which catches the backslash, if it appears zero or more times :) But then again,
    "if header :regex "eCentrum-Score_Stars" "^\\\{2,5}"" works, but I didn't test what does it match.

     
  • Heiko Hund

    Heiko Hund - 2009-05-26
    • labels: --> Parser
    • milestone: --> svn_trunk
    • assigned_to: nobody --> heikoh
     

Log in to post a comment.