Skip to content

Commit cb38770

Browse files
committed
kompose: Replace regex with simple parsing
Signed-off-by: Evangelos Skopelitis <[email protected]>
1 parent c3b558d commit cb38770

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

kompose/src/kompose.tsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,34 @@ export function getKomposeOutput(logs: string) {
5656
isError: false,
5757
};
5858

59-
const errorMatch = logs.match(/KOMPOSE_ERROR=(.+)__ENDERROR__/g);
60-
if (!!errorMatch) {
61-
output.isError = true;
62-
output.data = errorMatch[0].slice('KOMPOSE_ERROR='.length, -'__ENDERROR__'.length);
63-
return output;
59+
// Look for the error block
60+
const errorStart = logs.indexOf('KOMPOSE_ERROR=');
61+
if (errorStart !== -1) {
62+
const errorEnd = logs.indexOf('__ENDERROR__', errorStart);
63+
if (errorEnd !== -1) {
64+
output.isError = true;
65+
output.data = logs.slice(errorStart + 'KOMPOSE_ERROR='.length, errorEnd);
66+
return output;
67+
}
6468
}
6569

66-
const match = logs.match(/KOMPOSE_OUTPUT=([A-Za-z0-9\s=]+)__ENDOUTPUT__/g);
67-
if (!!match) {
68-
const komposeYAML = atob(
69-
match[0].slice('KOMPOSE_OUTPUT='.length, -'__ENDOUTPUT__'.length).replace(/ /g, '\n')
70-
);
71-
output.data = komposeYAML;
72-
} else {
73-
output.isError = true;
74-
output.data = 'Failed to get any output from conversion.';
70+
// Look for the output block
71+
const outputStart = logs.indexOf('KOMPOSE_OUTPUT=');
72+
if (outputStart !== -1) {
73+
const outputEnd = logs.indexOf('__ENDOUTPUT__', outputStart);
74+
if (outputEnd !== -1) {
75+
const encoded = logs.slice(outputStart + 'KOMPOSE_OUTPUT='.length, outputEnd);
76+
try {
77+
output.data = atob(encoded.replace(/ /g, '\n'));
78+
} catch (e) {
79+
output.isError = true;
80+
output.data = 'Failed to decode kompose output.';
81+
}
82+
return output;
83+
}
7584
}
7685

86+
output.isError = true;
87+
output.data = 'Failed to get any output from conversion.';
7788
return output;
7889
}

0 commit comments

Comments
 (0)