teemtee / fmf

Flexible Metadata Format
GNU General Public License v2.0
22 stars 28 forks source link

Support escaping `|` and `&` in `utils.filter()` #220

Closed psss closed 5 months ago

psss commented 10 months ago

Add support for escaping boolean operators using the back slash character \ to allow for example regular expression grouping.

Pull Request Checklist

The-Mule commented 6 months ago

@lukaszachy Any regexp where | is quite common, e.g. tmt test ls --filter 'name: (/setup\|/functional).*'.

lukaszachy commented 6 months ago

So re.sub doesn't work as expected, or? I'd assume that it intention is to 'undo' the escaping.

BTW it would be really good to see this covered in unit tests...

import re

>>> clause = re.split(r"\s*(?<!\\)\|\s*", r'foo\|bar|baz')[0]
>>> clause
'foo\\|bar'
>>> re.sub(r"\|", "|", clause)
'foo\\|bar'
psss commented 6 months ago

It's split of the filter() clause versus regular expression. See my comment in the related issue reported by @kkaarreell.

psss commented 6 months ago

Let's include escaping of & as well.

martinhoyer commented 5 months ago

Found this PR only after commenting at https://github.com/teemtee/fmf/pull/219#discussion_r1624484311