Skip to content

Commit 8b57d7e

Browse files
committed
parser: remove regexp for comment matching
Assumes input is single-line. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent fb5814d commit 8b57d7e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

frontend/dockerfile/parser/parser.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ type Heredoc struct {
114114
var (
115115
dispatch map[string]func(string, *directives) (*Node, map[string]bool, error)
116116
reWhitespace = regexp.MustCompile(`[\t\v\f\r ]+`)
117-
reComment = regexp.MustCompile(`^#.*$`)
118117
reHeredoc = regexp.MustCompile(`^(\d*)<<(-?)([^<]*)$`)
119118
reLeadingTabs = regexp.MustCompile(`(?m)^\t+`)
120119
)
@@ -487,7 +486,10 @@ func ChompHeredocContent(src string) string {
487486
}
488487

489488
func trimComments(src []byte) []byte {
490-
return reComment.ReplaceAll(src, []byte{})
489+
if !isComment(src) {
490+
return src
491+
}
492+
return nil
491493
}
492494

493495
func trimLeadingWhitespace(src []byte) []byte {
@@ -501,7 +503,8 @@ func trimNewline(src []byte) []byte {
501503
}
502504

503505
func isComment(line []byte) bool {
504-
return reComment.Match(trimLeadingWhitespace(trimNewline(line)))
506+
line = trimLeadingWhitespace(line)
507+
return len(line) > 0 && line[0] == '#'
505508
}
506509

507510
func isEmptyContinuationLine(line []byte) bool {

0 commit comments

Comments
 (0)