semgrep / semgrep

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.

Home Page:https://semgrep.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python: empty f-string is not matched by "..." pattern

GrosQuildu opened this issue · comments

Describe the bug
For Python, the "..." pattern does not match empty f-strings (f""). This seems to be an inconsistency.

To Reproduce
https://semgrep.dev/playground/s/yyRjO

rules:
  - id: python-fstring
    languages:
      - python
    severity: ERROR
    patterns:
      - pattern: $X = "..."
a = "asd"
b = ""
c = f"asd"
d = f""
e = f"{2+2}"

The a, b, and c lines are matched, d and e lines are not matched.

Expected behavior
I would expect the "..." pattern to match empty f-strings, because the pattern matches not-empty, constant f-strings already.

What is the priority of the bug to you?

  • P0: blocking your adoption of Semgrep or workflow
  • P1: important to fix or quite annoying
  • [X P2: regular bug that should get fixed

Use case
The bug makes us to write additional pattern-not cases, so it is a minor inconvenience. See trailofbits/semgrep-rules#39 (comment)