From a91a45289848be9116eb490c7bb8cfb71c2ba743 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Thu, 28 Jul 2022 11:33:54 -0300 Subject: [PATCH 1/6] Add trim function to validate LG expressions --- .../expressionValidation/validation.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts index 75598681a3..4949615e4c 100644 --- a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts +++ b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts @@ -20,6 +20,27 @@ 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); + } + + result = result.trim(); + + if (result.startsWith('$')) { + result = result.substring(1); + } + + result = result.trim(); + + if (result.startsWith('{') && result.endsWith('}')) { + result = result.substring(1, result.length - 1); + } + + return result.trim(); +}; + export const checkStringExpression = (exp: string, isStringType: boolean): number => { const origin = exp.trim(); const containsEqual = origin.startsWith('='); @@ -28,7 +49,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 => { From d545bd19e2bdbda00b7c86795c22be9ea5e55c15 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Thu, 28 Jul 2022 14:59:31 -0300 Subject: [PATCH 2/6] Add unit test --- .../__tests__/validations/expressionValidation.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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." + ); + } + }); }); From 13f803284f13c535dab1e9b34f2a032f57bb0600 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Mon, 1 Aug 2022 10:07:53 -0300 Subject: [PATCH 3/6] Improve trimExpression method --- .../validations/expressionValidation/validation.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts index 4949615e4c..660eb0479f 100644 --- a/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts +++ b/Composer/packages/lib/indexers/src/validations/expressionValidation/validation.ts @@ -23,22 +23,18 @@ export const addReturnType = (currentType: number, newType: number) => { export const trimExpression = (expression: string): string => { let result = expression.trim(); if (result.startsWith('=')) { - result = result.substring(1); + result = result.substring(1).trim(); } - result = result.trim(); - if (result.startsWith('$')) { - result = result.substring(1); + result = result.substring(1).trim(); } - result = result.trim(); - if (result.startsWith('{') && result.endsWith('}')) { - result = result.substring(1, result.length - 1); + result = result.substring(1, result.length - 1).trim(); } - return result.trim(); + return result; }; export const checkStringExpression = (exp: string, isStringType: boolean): number => { From c448cc1052840de371189bd16caeca3c0c173220 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Thu, 27 Oct 2022 14:54:04 -0300 Subject: [PATCH 4/6] Update yarn-berry.lock files --- extensions/azurePublish/yarn-berry.lock | 4 ++-- extensions/azurePublishNew/yarn-berry.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/azurePublish/yarn-berry.lock b/extensions/azurePublish/yarn-berry.lock index fd32472569..ef806a274f 100644 --- a/extensions/azurePublish/yarn-berry.lock +++ b/extensions/azurePublish/yarn-berry.lock @@ -1923,7 +1923,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=3ed14c&locator=azurePublish%40workspace%3A." + resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=a7b36f&locator=azurePublish%40workspace%3A." dependencies: "@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d adaptive-expressions: 4.12.0-rc1 @@ -1932,7 +1932,7 @@ __metadata: tslib: 2.4.0 peerDependencies: "@bfc/shared": "*" - checksum: ffc95d7cf9fc29427c3d09588d126026b7b9a76e01141320158854b0f1f973b7c70dac03120a396c2d6ae9d0f33b1557e1c60aedc96630e2fd6a8fa96484fdc6 + checksum: 9a5b961c3995f1d9b36745fefbf9d105ce0b19f75f917dc732fe863061e3081267830fe28b7a89ccb9e85a338d531c973d58ba43d16427d5ed1ab26f6e0a60fb languageName: node linkType: hard diff --git a/extensions/azurePublishNew/yarn-berry.lock b/extensions/azurePublishNew/yarn-berry.lock index ceeede1ec2..8d76a30c6a 100644 --- a/extensions/azurePublishNew/yarn-berry.lock +++ b/extensions/azurePublishNew/yarn-berry.lock @@ -1918,7 +1918,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=3ed14c&locator=azure-publish-new%40workspace%3A." + resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=a7b36f&locator=azure-publish-new%40workspace%3A." dependencies: "@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d adaptive-expressions: 4.12.0-rc1 @@ -1927,7 +1927,7 @@ __metadata: tslib: 2.4.0 peerDependencies: "@bfc/shared": "*" - checksum: ffc95d7cf9fc29427c3d09588d126026b7b9a76e01141320158854b0f1f973b7c70dac03120a396c2d6ae9d0f33b1557e1c60aedc96630e2fd6a8fa96484fdc6 + checksum: 9a5b961c3995f1d9b36745fefbf9d105ce0b19f75f917dc732fe863061e3081267830fe28b7a89ccb9e85a338d531c973d58ba43d16427d5ed1ab26f6e0a60fb languageName: node linkType: hard From f86d6ac7ba77d836c99725396268a4e6ab54a723 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Mon, 23 Jan 2023 16:31:17 -0300 Subject: [PATCH 5/6] Update yarn-berry.lock files --- extensions/azurePublish/yarn-berry.lock | 4 ++-- extensions/azurePublishNew/yarn-berry.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/azurePublish/yarn-berry.lock b/extensions/azurePublish/yarn-berry.lock index 45783b7d61..827699542b 100644 --- a/extensions/azurePublish/yarn-berry.lock +++ b/extensions/azurePublish/yarn-berry.lock @@ -1923,7 +1923,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=07822c&locator=azurePublish%40workspace%3A." + resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=c64ac6&locator=azurePublish%40workspace%3A." dependencies: "@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d adaptive-expressions: ^4.18.0 @@ -1932,7 +1932,7 @@ __metadata: tslib: 2.4.0 peerDependencies: "@bfc/shared": "*" - checksum: e75d94610a3de51ff52b7ec165e028d9a9ebaceff8db361acbdacc83fdd8d15ee4320bf0771ddf7d163bcb295ed31523a0c3fa1e49bb68a68d4aebbce85b2470 + checksum: f46fb76816d3addae9b9519255f4256b636f647c5b0cd985c0c6a7fde7e7f1bf88b2089e2368955ce36f4e466281b9f057a717bafb453f18d3a018c83f15f1b4 languageName: node linkType: hard diff --git a/extensions/azurePublishNew/yarn-berry.lock b/extensions/azurePublishNew/yarn-berry.lock index e689312a95..2d7957749e 100644 --- a/extensions/azurePublishNew/yarn-berry.lock +++ b/extensions/azurePublishNew/yarn-berry.lock @@ -1918,7 +1918,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=07822c&locator=azure-publish-new%40workspace%3A." + resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=c64ac6&locator=azure-publish-new%40workspace%3A." dependencies: "@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d adaptive-expressions: ^4.18.0 @@ -1927,7 +1927,7 @@ __metadata: tslib: 2.4.0 peerDependencies: "@bfc/shared": "*" - checksum: e75d94610a3de51ff52b7ec165e028d9a9ebaceff8db361acbdacc83fdd8d15ee4320bf0771ddf7d163bcb295ed31523a0c3fa1e49bb68a68d4aebbce85b2470 + checksum: f46fb76816d3addae9b9519255f4256b636f647c5b0cd985c0c6a7fde7e7f1bf88b2089e2368955ce36f4e466281b9f057a717bafb453f18d3a018c83f15f1b4 languageName: node linkType: hard From be4679114c5c0db32437c6df6ff12304df6fec75 Mon Sep 17 00:00:00 2001 From: Joel Mut Date: Wed, 15 May 2024 15:34:12 -0300 Subject: [PATCH 6/6] Fix hash --- extensions/azurePublish/yarn-berry.lock | 4 ++-- extensions/azurePublishNew/yarn-berry.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/azurePublish/yarn-berry.lock b/extensions/azurePublish/yarn-berry.lock index b2a6c2b587..9cae155c26 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 1c39dd0bac..c3629452c1 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