Skip to content

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

Merged
maciejpirog merged 1 commit intoopengrep:opengrep/mainfrom
abezdina:da/dockerfile-fix-crlf-and-comment-parsing
Feb 17, 2026
Merged

dockerfile: fix comment regex to preserve line continuation backslash#2
maciejpirog merged 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
Copy link

@maciejpirog maciejpirog left a comment

Choose a reason for hiding this comment

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

LGTM

@maciejpirog maciejpirog merged commit b149e3a into opengrep:opengrep/main Feb 17, 2026
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.

3 participants