Skip to content

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Feb 23, 2025

A regex in this file (on line 143) triggered a code scan security warning:(https://github.com/quantumlib/Cirq/security/code-scanning/97):

def find_rst_code_snippets(content: str) -> List[Tuple[str, int]]:
    snippets = find_code_snippets(
        r'\n.. code-block:: python\n(?:\s+:.*?\n)*\n(.*?)(?:\n\S|\Z)', content
                                           ^^^

This part of the regular expression may cause exponential
backtracking on strings starting with '\naa code-block:: python\n :'
and containing many repetitions of '\n :'.

This was in code for testing reStructuredText files. Since we no longer have any .rst files in the code base, it seemed more sensible to remove all the rST-specific code in here. Doing that not only resolves the code scan warning – it also reduces the maintenance burden going forward.

A regex in this file (on line 143) triggered a code scan security
warning:(https://github.com/quantumlib/Cirq/security/code-scanning/97):

```python
def find_rst_code_snippets(content: str) -> List[Tuple[str, int]]:
    snippets = find_code_snippets(
        r'\n.. code-block:: python\n(?:\s+:.*?\n)*\n(.*?)(?:\n\S|\Z)', content
```
> This part of the regular expression may cause exponential
> backtracking on strings starting with '\naa code-block:: python\n :'
> and containing many repetitions of '\n :'.

This was in code for testing reStructuredText files. Since we no
longer have any `.rst` files in the code base, it seemed more sensible
to remove all the rST-specific code in here. Not only does that
resolve the code scan warning; it also reduces the maintenance burden
going forward.
@CirqBot CirqBot added the size: M 50< lines changed <250 label Feb 23, 2025
@mhucka mhucka self-assigned this Feb 23, 2025
@mhucka mhucka added the kind/health For CI/testing/release process/refactoring/technical debt items label Feb 23, 2025
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.17%. Comparing base (a2bf6e8) to head (d47b845).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7085      +/-   ##
==========================================
- Coverage   98.18%   98.17%   -0.01%     
==========================================
  Files        1089     1089              
  Lines       95237    95210      -27     
==========================================
- Hits        93508    93474      -34     
- Misses       1729     1736       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mhucka mhucka requested a review from pavoljuhas February 23, 2025 21:40
@mhucka mhucka marked this pull request as ready for review February 23, 2025 21:40
@mhucka mhucka requested review from vtomole and a team as code owners February 23, 2025 21:40
@mhucka mhucka enabled auto-merge February 23, 2025 21:40
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Thanks!

@mhucka mhucka added this pull request to the merge queue Feb 24, 2025
Merged via the queue into quantumlib:main with commit f30e6d4 Feb 24, 2025
38 checks passed
@mhucka mhucka deleted the mh-fix-regex-warning branch February 24, 2025 05:50
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
A regex in this file (on line 143) triggered a code scan security
warning:(https://github.com/quantumlib/Cirq/security/code-scanning/97):

```python
def find_rst_code_snippets(content: str) -> List[Tuple[str, int]]:
    snippets = find_code_snippets(
        r'\n.. code-block:: python\n(?:\s+:.*?\n)*\n(.*?)(?:\n\S|\Z)', content
```
> This part of the regular expression may cause exponential
> backtracking on strings starting with '\naa code-block:: python\n :'
> and containing many repetitions of '\n :'.

This was in code for testing reStructuredText files. Since we no
longer have any `.rst` files in the code base, it seemed more sensible
to remove all the rST-specific code in here. Not only does that
resolve the code scan warning; it also reduces the maintenance burden
going forward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/health For CI/testing/release process/refactoring/technical debt items size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants