Skip to content

Potential fix for code scanning alert no. 1: Inefficient regular expression - #135

Draft
ronaldosc wants to merge 2 commits into
masterfrom
fix-regex-import-pattern
Draft

ronaldosc wants to merge 2 commits into
masterfrom
fix-regex-import-pattern

Conversation

@ronaldosc

Copy link
Copy Markdown
Collaborator

Potential fix for https://github.com/detrohutt/babel-plugin-import-graphql/security/code-scanning/1

To fix this safely, rewrite the trailing newline matcher so each repetition consumes exactly one line break unit without overlap between alternatives.
In plugin/constants.js line 3, replace:

  • (?:\r\n|\r|\n)*

with:

  • (?:\r?\n)*

This preserves behavior for newline sequences at the end (matches zero or more LF or CRLF line breaks), and removes the ambiguous \r\n vs \r/\n branching that causes excessive backtracking. No new imports, helpers, or dependencies are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ession

**Inefficient regular expression**  
This part of the regular expression ( ?:\ r\n | \r | \n ) may cause exponential backtracking on strings starting with '#import 'a'' and containing many repetitions of ` '\r\n' `.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@ronaldosc ronaldosc self-assigned this Jul 5, 2026
Correction in Regex cause it was allowing open with `"` and closing with `'` for better consistence.  
It had a redundance in newline pattern.
Comment thread plugin/constants.js
export const newlinePattern =
/(?:\r\n?|\n)+/g
export const importPattern =
/^# *import +(?:\* +from +)?(['"`])([^'"`\r\n]*)\1(?:\r\n?|\n)*$/gm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants