Skip to content

Commit 74fab2f

Browse files
committed
fix: regex for heredoc
1 parent dea80d7 commit 74fab2f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/parseDockerfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ module.exports = function parseDockerfile(content, options = {}) {
3838
: Math.max(startIdx, nextStartIdx - 1)
3939

4040
// Recover the true start by scanning upward from endIdx until the header line (instruction keyword) is found
41-
const startsWithName = (line, name) =>
42-
new RegExp(`^\\s*${name}\\b`, "i").test(line)
41+
const escapeRegExp = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
42+
const startsWithName = (line, name) => {
43+
if (!name) return false
44+
const re = new RegExp(`^\\s*${escapeRegExp(name)}\\b`, "i")
45+
return re.test(line)
46+
}
4347

4448
let startIdxScan = endIdx
4549
if (instruction.name !== "COMMENT") {

0 commit comments

Comments
 (0)