Skip to content

Commit

Permalink
Add in proper handling of spaces and quotes in ISVC parsing
Browse files Browse the repository at this point in the history
This adds a rudimentary parser that should handle most cases for
inferenceservice argument parsing. Note, I'm not a JS expert, so
it's possible there's some degerenate edge case with this, but
in testing it worked fine
  • Loading branch information
Xaenalt committed Dec 18, 2024
1 parent 2ee880d commit 6c3ffe4
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions frontend/src/api/k8s/inferenceServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const assembleInferenceService = (
const dataConnectionKey = secretKey || dataConnection;

const nonEmptyArgs = servingRuntimeArgs?.filter(Boolean) || [];
// If we have nonEmptyArgs, ensure that we properly handle separating args
let splitArgs: string[] = [];
if (nonEmptyArgs.length > 0) {
for (let i = 0; i < nonEmptyArgs.length; i++) {
splitArgs = splitArgs.concat(parseCommandLine(nonEmptyArgs[i]));
}
}
const nonEmptyEnvVars = servingRuntimeEnvVars?.filter((ev) => ev.name) || [];

const updateInferenceService: InferenceServiceKind = inferenceService
Expand Down Expand Up @@ -87,7 +94,7 @@ export const assembleInferenceService = (
path,
},
}),
args: nonEmptyArgs,
args: splitArgs,
env: nonEmptyEnvVars,
},
},
Expand Down Expand Up @@ -135,7 +142,7 @@ export const assembleInferenceService = (
path,
},
}),
args: nonEmptyArgs,
args: splitArgs,
env: nonEmptyEnvVars,
},
},
Expand Down Expand Up @@ -325,3 +332,25 @@ export const deleteInferenceService = (
opts,
),
);


Check failure on line 336 in frontend/src/api/k8s/inferenceServices.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Delete `⏎`
function parseCommandLine(input: string): string[] {
const args: string[] = [];
const regex = /(?:[^\s"']+|"[^"]*"|'[^']*')+/g;
let match: RegExpExecArray | null;

while ((match = regex.exec(input)) !== null) {
let arg: string = match[0];

// Remove surrounding quotes if any
if (arg.startsWith('"') && arg.endsWith('"')) {
arg = arg.slice(1, -1).replace(/\\"/g, '"'); // Unescape double quotes
} else if (arg.startsWith("'") && arg.endsWith("'")) {
arg = arg.slice(1, -1); // Remove single quotes
}

args.push(arg);
}

return args;
}

Check failure on line 356 in frontend/src/api/k8s/inferenceServices.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Insert `⏎`

0 comments on commit 6c3ffe4

Please sign in to comment.