Skip to content

Commit

Permalink
make the number normalization more robust
Browse files Browse the repository at this point in the history
when a number field has its value removed in the UI, the value will be reset to the default, but will instead be the empty string. Empty strings in JS are parsed as 0, which is a problem for values, that may not be 0.
  • Loading branch information
pschichtel committed May 24, 2023
1 parent 137c9d2 commit c9deae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion extensions/vier-cognitive-voice-gateway/src/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ function toNumberOrUndefined(numeric: number | string | undefined | null): numbe
return undefined;
}
if (typeof numeric === 'string') {
const parsedNumber = Number(numeric);
const trimmed = numeric.trim()
if (trimmed === '') {
return undefined
}
const parsedNumber = Number(trimmed);
return isNaN(parsedNumber) ? undefined : parsedNumber;
}
if (typeof numeric !== 'number') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const promptForNumberNode = createNodeDescriptor({
});
}

const maxDigits = normalizeInteger(config.maxDigits, 1, undefined);
const payload = {
status: 'prompt',
timeout: convertDurationFromSecondsToMillis(config.timeout),
Expand All @@ -132,8 +133,8 @@ export const promptForNumberNode = createNodeDescriptor({
type: {
name: 'Number',
submitInputs: submitInputs,
minDigits: normalizeInteger(config.minDigits, undefined, undefined),
maxDigits: normalizeInteger(config.maxDigits, undefined, undefined),
minDigits: normalizeInteger(config.minDigits, undefined, maxDigits),
maxDigits: maxDigits,
},
};
api.say(config.text, payload);
Expand Down

0 comments on commit c9deae0

Please sign in to comment.