Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(build): continue a Dockerfile line over blanks, CR and empty lines
Yudhi Armyndharis4389d5aa11d1
diff --git a/scripts/check-dockerignore.mjs b/scripts/check-dockerignore.mjsindex 558e3d985..69f089884 100644--- a/scripts/check-dockerignore.mjs+++ b/scripts/check-dockerignore.mjs@@ -171,12 +171,13 @@ const errors = [];// them then broke the image build rather than this check. A copy from another stage, a flag, the// destination, a remote ADD source and `.` (the whole context) are not inputs.// Comment lines go first, as in BuildKit: a comment is never continued, so one that ends in a backslash must-// not swallow the instruction below it, and one inside a continued instruction drops out of it.+// not swallow the instruction below it, and one inside a continued instruction drops out of it. A+// continuation is a backslash, optional blanks and CR, the line end, and any blank lines after it.const dockerfile = readFileSync(new URL('Dockerfile', root), 'utf8').split('\n').filter(line => !/^\s*#/.test(line)).join('\n')- .replace(/\\\n/g, ' ');+ .replace(/\\[ \t\r]*\n(?:[ \t\r]*\n)*/g, ' ');const wildcard = /[*?[]/;function copyInputs(source) {// Remote, as in BuildKit, which matches the scheme in lower case only: ADD HTTPS://x/y names a context path.diff --git a/scripts/check-dockerignore.spec.mjs b/scripts/check-dockerignore.spec.mjsindex 68ce53f0f..b51c6905b 100644--- a/scripts/check-dockerignore.spec.mjs+++ b/scripts/check-dockerignore.spec.mjs@@ -104,12 +104,22 @@ test('a rule spelled ./data/ keeps data/ out of the context as data/ does', () =});test('an instruction continued over several lines is read whole', () => {- const run = runGate({- Dockerfile: 'COPY control.txt \\\n scripts/new.js \\\n ./scripts/\n',- '.dockerignore': `${REAL_DOCKERIGNORE}\nscripts/new.js\n`,- });- assert.equal(run.status, 1, run.out);- assert.match(run.out, /rejects 'scripts\/new\.js'/);+ // Each form builds in real BuildKit, which continues over a backslash followed by blanks or a CR, and+ // skips blank lines inside the instruction.+ const forms = {+ 'a backslash': 'COPY control.txt \\\n scripts/new.js \\\n ./scripts/\n',+ 'a backslash and a blank': 'COPY control.txt \\ \n scripts/new.js ./scripts/\n',+ 'a backslash and two blanks': 'COPY control.txt \\ \n scripts/new.js ./scripts/\n',+ 'a backslash and a tab': 'COPY control.txt \\\t\n scripts/new.js ./scripts/\n',+ 'CRLF line ends': 'COPY control.txt \\\r\n scripts/new.js ./scripts/\r\n',+ 'an empty line inside': 'COPY control.txt \\\n\n scripts/new.js ./scripts/\n',+ 'a blank line inside': 'COPY control.txt \\\n \n scripts/new.js ./scripts/\n',+ };+ for (const [name, dockerfile] of Object.entries(forms)) {+ const run = runGate({ Dockerfile: dockerfile, '.dockerignore': `${REAL_DOCKERIGNORE}\nscripts/new.js\n` });+ assert.equal(run.status, 1, `${name}: ${run.out}`);+ assert.match(run.out, /rejects 'scripts\/new\.js'/, `${name}: ${run.out}`);+ }});test('a comment ends with its line, whatever it ends in, and is not part of a continued instruction', () => {