Skip to content

Commit

Permalink
fix: [#9151] LG for 'choices' field in multi choice input results in …
Browse files Browse the repository at this point in the history
…Warning (#9321)

* Add trim function to validate LG expressions

* Add unit test

* Improve trimExpression method

* Update yarn-berry.lock files

* Update yarn-berry.lock files

* Fix hash

---------

Co-authored-by: Joel Mut <62260472+sw-joelmut@users.noreply.github.com>
Co-authored-by: Joel Mut <joel.mut@southworks.com>
Co-authored-by: Eugene <EOlonov@gmail.com>
  • Loading branch information
4 people authored May 16, 2024
1 parent d245206 commit bc5cc73
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe('validate expression', () => {
const result = checkExpression("=concat('test', '1')", true, [ReturnType.String]);
expect(result).toBe(24);
});

it('use LG expressions will not throw error', () => {
try {
checkExpression('${LGChoiceOptions()}', true, [ReturnType.Number]);
} catch (error) {
expect(error.message).toBe(
"LGChoiceOptions does not have an evaluator, it's not a built-in function or a custom function."
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ export const addReturnType = (currentType: number, newType: number) => {
return currentType | newType;
};

export const trimExpression = (expression: string): string => {
let result = expression.trim();
if (result.startsWith('=')) {
result = result.substring(1).trim();
}

if (result.startsWith('$')) {
result = result.substring(1).trim();
}

if (result.startsWith('{') && result.endsWith('}')) {
result = result.substring(1, result.length - 1).trim();
}

return result;
};

export const checkStringExpression = (exp: string, isStringType: boolean): number => {
const origin = exp.trim();
const containsEqual = origin.startsWith('=');
Expand All @@ -28,7 +45,9 @@ export const checkStringExpression = (exp: string, isStringType: boolean): numbe
return ReturnType.String;
}

return Expression.parse(containsEqual ? origin.substring(1) : origin).returnType;
const trimmedOrigin = trimExpression(origin);

return Expression.parse(trimmedOrigin).returnType;
};

export const checkExpression = (exp: any, required: boolean, types: number[]): number => {
Expand Down
4 changes: 2 additions & 2 deletions extensions/azurePublish/yarn-berry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ __metadata:

"@bfc/indexers@file:../../Composer/packages/lib/indexers::locator=azurePublish%40workspace%3A.":
version: 0.0.0
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=f8e51f&locator=azurePublish%40workspace%3A."
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=5e1a82&locator=azurePublish%40workspace%3A."
dependencies:
"@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d
adaptive-expressions: ^4.18.0
Expand All @@ -2003,7 +2003,7 @@ __metadata:
tslib: 2.6.2
peerDependencies:
"@bfc/shared": "*"
checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1
checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7
languageName: node
linkType: hard

Expand Down
4 changes: 2 additions & 2 deletions extensions/azurePublishNew/yarn-berry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ __metadata:

"@bfc/indexers@file:../../Composer/packages/lib/indexers::locator=azure-publish-new%40workspace%3A.":
version: 0.0.0
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=f8e51f&locator=azure-publish-new%40workspace%3A."
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=5e1a82&locator=azure-publish-new%40workspace%3A."
dependencies:
"@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d
adaptive-expressions: ^4.18.0
Expand All @@ -2040,7 +2040,7 @@ __metadata:
tslib: 2.6.2
peerDependencies:
"@bfc/shared": "*"
checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1
checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7
languageName: node
linkType: hard

Expand Down

0 comments on commit bc5cc73

Please sign in to comment.