Skip to content

Commit 229a184

Browse files
dockerfile: fix comment regex to preserve line continuation backslash
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.
1 parent bbacb5d commit 229a184

File tree

4 files changed

+5092
-5011
lines changed

4 files changed

+5092
-5011
lines changed

fyi/semgrep-grammars/src/tree-sitter-dockerfile/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,6 @@ module.exports = grammar({
493493

494494
_non_newline_whitespace: () => token.immediate(/[\t ]+/),
495495

496-
comment: () => /#.*/,
496+
comment: () => /#[^\\\n]*(?:\\.[^\\\n]*)*/,
497497
},
498498
});

lib/Boilerplate.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ let map_source_file (env : env) (xs : CST.source_file) =
10851085
) xs)
10861086

10871087
let map_comment (env : env) (tok : CST.comment) =
1088-
(* pattern #.* *) token env tok
1088+
(* pattern #[^\\\n]*(?:\\.[^\\\n]*\
1089+
)* *) token env tok
10891090

10901091
let map_line_continuation (env : env) (tok : CST.line_continuation) =
10911092
(* pattern \\[ \t]*\n *) token env tok

lib/CST.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ and onbuild_instruction = (pat_onbu * instruction)
541541

542542
type source_file = (instruction * Token.t (* "\n" *)) list (* zero or more *)
543543

544-
type comment (* inlined *) = Token.t (* pattern #.* *)
544+
type comment (* inlined *) =
545+
Token.t (* pattern #[^\\\n]*(?:\\.[^\\\n]*
546+
)* *)
545547

546548
type line_continuation (* inlined *) = Token.t (* pattern \\[ \t]*\n *)
547549

0 commit comments

Comments
 (0)