Skip to content

Commit 9bee7ac

Browse files
authored
fix: edge cases when boolean include-input got converted into string when it's supposed to be boolean (#1291)
* fix: edge cases when boolean include-input got converted into string when it's supposed to be boolean * refactor: arg have been renamed and anyways it's not required
1 parent 70d2462 commit 9bee7ac

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ export class Parser {
337337

338338
case "number":
339339
case "boolean":
340+
if ((secondChar == "\"" && lastChar == "\"") && firstChar != "\\") {
341+
return firstChar + inputValue;
342+
}
340343
return firstTwoChar + inputValue + lastChar;
341344

342345
default:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
spec:
3+
inputs:
4+
boolean_input:
5+
type: boolean
6+
---
7+
default:
8+
interruptible: $[[ inputs.boolean_input ]] # This should be !!bool and not !!str
9+
scan-website:
10+
script:
11+
- echo $[[ inputs.boolean_input]]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
include:
3+
- local: '/.gitlab-ci-input-template.yml'
4+
inputs:
5+
boolean_input: true
6+
stages:
7+
- test

tests/test-cases/include-inputs/integration.include-inputs.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ test_job:
205205
expect(writeStreams.stdoutLines[0]).toEqual(expected);
206206
});
207207

208+
test("include-inputs for type boolean", async () => {
209+
const writeStreams = new WriteStreamsMock();
210+
await handler({
211+
cwd: "tests/test-cases/include-inputs/input-templates/types/boolean",
212+
preview: true,
213+
jsonSchemaValidation: true, // this test depends on the json schema validation, do not set to false
214+
}, writeStreams);
215+
216+
const expected = `---
217+
stages:
218+
- .pre
219+
- test
220+
- .post
221+
scan-website:
222+
script:
223+
- echo true`;
224+
225+
expect(writeStreams.stdoutLines[0]).toEqual(expected);
226+
});
227+
208228
test("include-inputs inputs validation for boolean", async () => {
209229
try {
210230
const writeStreams = new WriteStreamsMock();

tests/test-cases/script-blank/integration.script-blank.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ test("script-blank <test-job>", async () => {
1414
await expect(handler({
1515
cwd: "tests/test-cases/script-blank",
1616
job: ["test-job"],
17-
enableJsonSchemaValidation: false,
1817
}, writeStreams)).rejects.toThrow(chalk`{blue test-job} has empty script`);
1918
});

0 commit comments

Comments
 (0)