Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly parse tmt inputs that contain = (e.g. BASE64 encoded strings) #179

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/schema/input.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/schema/input.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/schema/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ const stringToArraySchema = z.string().transform(str => str.split(';'));
const keyValueArrayToObjectSchema = stringToArraySchema.transform(arr => {
let obj: { [key: string]: string } = {};
arr.forEach(item => {
const [key, value] = item.split('=');
const [key, ...values] = item.split('=');
// ''.split('=') returns [''] ; we have to check for this case
if (key === '' && value === undefined) return;
// 'abc'.split('=') returns ['abc'] ; we have to check for this case
obj[key] = value ?? '';
if (key === '' && Array.isArray(values) && values.length === 0) return;
obj[key] = values.join('=');
});
return z.record(z.string(), z.string()).parse(obj);
});
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ describe('tmt variables/secrets/context input', () => {
});

test('Corner case input', () => {
const input = 'A=a;B=;=c;D;=';
const input = 'A=a;B=;=c;D;E=base64=;=';

expect(tmtEnvVarsSchema.parse(input)).toMatchInlineSnapshot(`
{
"": "",
"A": "a",
"B": "",
"D": "",
"E": "base64=",
}
`);
expect(tmtEnvSecretsSchema.parse(input)).toMatchInlineSnapshot(`
Expand All @@ -105,6 +106,7 @@ describe('tmt variables/secrets/context input', () => {
"A": "a",
"B": "",
"D": "",
"E": "base64=",
}
`);
expect(tmtContextInputSchema.parse(input)).toMatchInlineSnapshot(`
Expand All @@ -113,6 +115,7 @@ describe('tmt variables/secrets/context input', () => {
"A": "a",
"B": "",
"D": "",
"E": "base64=",
}
`);
});
Expand Down
Loading