Skip to content

Commit 42f28f2

Browse files
committed
fix: improve solidity avoiding regex that could break
1 parent 74fab2f commit 42f28f2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib/parseDockerfile.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ 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 escapeRegExp = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
41+
const headerToken = (line) => {
42+
if (!line) return null
43+
const m = line.match(/^\s*([A-Za-z]+)/)
44+
return m ? m[1] : null
45+
}
4246
const startsWithName = (line, name) => {
4347
if (!name) return false
44-
const re = new RegExp(`^\\s*${escapeRegExp(name)}\\b`, "i")
45-
return re.test(line)
48+
const tok = headerToken(line)
49+
return tok ? tok.toUpperCase() === String(name).toUpperCase() : false
4650
}
4751

4852
let startIdxScan = endIdx

0 commit comments

Comments
 (0)