fix(striker-ui-api): handle quoted fence parameters with spaces

main
Tsu-ba-me 1 year ago
parent dc5b01f087
commit 6ceaaf5ec6
  1. 33
      striker-ui-api/src/lib/request_handlers/fence/getFence.ts

@ -20,16 +20,33 @@ export const getFence: RequestHandler = buildGetRequestHandler(
const afterQueryReturn: QueryResultModifierFunction | undefined = const afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [fenceUUID: string]: FenceOverview }>( buildQueryResultReducer<{ [fenceUUID: string]: FenceOverview }>(
(previous, [fenceUUID, fenceName, fenceAgent, fenceArgumentString]) => { (
const fenceParameters = fenceArgumentString previous,
.split(/\s+/) [fenceUUID, fenceName, fenceAgent, fenceParametersString],
.reduce<FenceParameters>((previous, parameterPair) => { ) => {
const [parameterId, parameterValue] = parameterPair.split(/=/); const fenceParametersArray = fenceParametersString.match(
/(?:[^\s'"]+|'[^']*'|"[^"]*")+/g,
);
previous[parameterId] = parameterValue.replace(/['"]/g, ''); if (!fenceParametersArray) return previous;
return previous; const fenceParameters = fenceParametersArray.reduce<FenceParameters>(
}, {}); (previousParameters, parameterString) => {
const parameterPair = parameterString.split(/=(.*)/, 2);
if (parameterPair.length !== 2) return previousParameters;
const [parameterId, parameterValue] = parameterPair;
previousParameters[parameterId] = parameterValue.replace(
/['"]/g,
'',
);
return previousParameters;
},
{},
);
stdout( stdout(
`${fenceAgent}: ${fenceName} (${fenceUUID})\n${JSON.stringify( `${fenceAgent}: ${fenceName} (${fenceUUID})\n${JSON.stringify(

Loading…
Cancel
Save