Skip to content

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

Merged
psss merged 1 commit into
mainfrom
escape-operators
Jun 5, 2024
Merged

psss merged 1 commit into
mainfrom
escape-operators

Conversation

@psss

@psss psss commented Jan 23, 2024 •

Copy link
Copy Markdown
Member

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

Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage

@psss psss added this to the 1.4 milestone Jan 23, 2024
@psss psss added the utils label Jan 23, 2024

@lukaszachy lukaszachy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add examples how this should be used? I'm not sure the re.sub is correct but hard to tell.

@The-Mule

Copy link
Copy Markdown

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

@lukaszachy

Copy link
Copy Markdown
Contributor

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

psss commented May 13, 2024

Copy link
Copy Markdown
Member Author

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

@psss

psss commented May 14, 2024

Copy link
Copy Markdown
Member Author

Let's include escaping of & as well.

@martinhoyer

Copy link
Copy Markdown
Contributor

Found this PR only after commenting at #219 (comment)

@psss
psss force-pushed the escape-operators branch from 1174981 to 749a5ab Compare June 4, 2024 16:58
@psss psss changed the title Add support for escaping | in utils.filter() Support escaping | and & in utils.filter() Jun 4, 2024
@psss
psss requested review from lukaszachy and martinhoyer June 4, 2024 16:59
Add support for escaping boolean operators using the back slash
character `\` to allow for example regular expression grouping.
@psss
psss force-pushed the escape-operators branch from 749a5ab to fe38c42 Compare June 4, 2024 17:01
@psss psss self-assigned this Jun 5, 2024
@psss
psss merged commit fe38c42 into main Jun 5, 2024
@psss
psss deleted the escape-operators branch June 5, 2024 08:21
@psss psss linked an issue Jun 5, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use parenthesis in --filter regexp

4 participants