Skip to content

dockerfile: fix comment regex to preserve line continuation backslash#2

Open
abezdina wants to merge 1 commit intoopengrep:opengrep/mainfrom
abezdina:da/dockerfile-fix-crlf-and-comment-parsing
Open

dockerfile: fix comment regex to preserve line continuation backslash#2
abezdina wants to merge 1 commit intoopengrep:opengrep/mainfrom
abezdina:da/dockerfile-fix-crlf-and-comment-parsing

Conversation

@abezdina
Copy link

Fix the comment regex in the tree-sitter Dockerfile grammar from /#.*/ to /#[^\\\n]*(?:\\.[^\\\n]*)*/ so that backslashes at the end of comment lines are not consumed by the comment token.

This allows LABEL continuation lines with interspersed comments to parse correctly:

LABEL key1=val1 \
    # a comment \
    key2=val2

Part of opengrep/opengrep#586 — fixes Dockerfile parser to correctly handle comments

Change the comment regex from /#.*/ to /#[^\\\n]*(?:\\.[^\\\n]*)*/
so that a trailing backslash on a comment line is NOT consumed as part
of the comment token.
@abezdina abezdina force-pushed the da/dockerfile-fix-crlf-and-comment-parsing branch from a5babc9 to 229a184 Compare February 14, 2026 08:31
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