From bc5cc73817881d4835f7c8ef68a6d6be905f88ee Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Thu, 16 May 2024 20:19:01 +0000 Subject: [PATCH] fix: [#9151] LG for 'choices' field in multi choice input results in 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 Co-authored-by: Eugene --- .../validations/expressionValidation.test.ts | 10 +++++++++ .../expressionValidation/validation.ts | 21 ++++++++++++++++++- extensions/azurePublish/yarn-berry.lock | 4 ++-- extensions/azurePublishNew/yarn-berry.lock | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts b/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts index a59edce2bc..205770561f 100644 --- a/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts +++ b/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts @@ -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." + ); + } + }); }); diff --git a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts index c9449a975f..2e2f1976e3 100644 --- a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts +++ b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts @@ -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('='); @@ -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 => { diff --git a/extensions/azurePublish/yarn-berry.lock b/extensions/azurePublish/yarn-berry.lock index 341fa33905..66e2f1a714 100644 --- a/extensions/azurePublish/yarn-berry.lock +++ b/extensions/azurePublish/yarn-berry.lock @@ -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 @@ -2003,7 +2003,7 @@ __metadata: tslib: 2.6.2 peerDependencies: "@bfc/shared": "*" - checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1 + checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7 languageName: node linkType: hard diff --git a/extensions/azurePublishNew/yarn-berry.lock b/extensions/azurePublishNew/yarn-berry.lock index 862eedbacd..538e2f4380 100644 --- a/extensions/azurePublishNew/yarn-berry.lock +++ b/extensions/azurePublishNew/yarn-berry.lock @@ -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 @@ -2040,7 +2040,7 @@ __metadata: tslib: 2.6.2 peerDependencies: "@bfc/shared": "*" - checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1 + checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7 languageName: node linkType: hard