From 62874a275b1d74c9dab5b5b19a6fd0a3fd9c8716 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 10 May 2024 10:52:33 +0200 Subject: [PATCH] Adds throwing error when SP URL is empty. Closes #6012 --- src/m365/spo/commands/folder/folder-set.spec.ts | 2 +- .../spo/commands/storageentity/storageentity-list.spec.ts | 2 +- .../spo/commands/storageentity/storageentity-remove.spec.ts | 2 +- .../spo/commands/storageentity/storageentity-set.spec.ts | 2 +- src/utils/validation.ts | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/m365/spo/commands/folder/folder-set.spec.ts b/src/m365/spo/commands/folder/folder-set.spec.ts index 20bf5f85752..d840bfc8b08 100644 --- a/src/m365/spo/commands/folder/folder-set.spec.ts +++ b/src/m365/spo/commands/folder/folder-set.spec.ts @@ -247,7 +247,7 @@ describe(commands.FOLDER_SET, () => { it('fails validation if the webUrl option is not valid', async () => { const actual = await command.validate({ options: { webUrl: 'abc', url: folderRelSiteUrl, name: newFolderName } }, commandInfo); - assert.strictEqual(actual, "abc is not a valid SharePoint Online site URL"); + assert.strictEqual(actual, "'abc' is not a valid SharePoint Online site URL."); }); it('passes validation when the url option specified', async () => { diff --git a/src/m365/spo/commands/storageentity/storageentity-list.spec.ts b/src/m365/spo/commands/storageentity/storageentity-list.spec.ts index bf492fd0a00..a0c864d19be 100644 --- a/src/m365/spo/commands/storageentity/storageentity-list.spec.ts +++ b/src/m365/spo/commands/storageentity/storageentity-list.spec.ts @@ -235,7 +235,7 @@ describe(commands.STORAGEENTITY_LIST, () => { it('rejects invalid SharePoint Online URL', async () => { const url = 'http://contoso'; const actual = await command.validate({ options: { appCatalogUrl: url } }, commandInfo); - assert.strictEqual(actual, `${url} is not a valid SharePoint Online site URL`); + assert.strictEqual(actual, `'${url}' is not a valid SharePoint Online site URL.`); }); it('fails validation when no SharePoint Online app catalog URL specified', async () => { diff --git a/src/m365/spo/commands/storageentity/storageentity-remove.spec.ts b/src/m365/spo/commands/storageentity/storageentity-remove.spec.ts index 89f709f2573..35468bc0216 100644 --- a/src/m365/spo/commands/storageentity/storageentity-remove.spec.ts +++ b/src/m365/spo/commands/storageentity/storageentity-remove.spec.ts @@ -194,7 +194,7 @@ describe(commands.STORAGEENTITY_REMOVE, () => { it('rejects invalid SharePoint Online URL', async () => { const url = 'http://contoso'; const actual = await command.validate({ options: { appCatalogUrl: url, key: 'prop' } }, commandInfo); - assert.strictEqual(actual, `${url} is not a valid SharePoint Online site URL`); + assert.strictEqual(actual, `'${url}' is not a valid SharePoint Online site URL.`); }); it('fails validation when no SharePoint Online app catalog URL specified', async () => { diff --git a/src/m365/spo/commands/storageentity/storageentity-set.spec.ts b/src/m365/spo/commands/storageentity/storageentity-set.spec.ts index 27ccf471c17..7bbd9e27896 100644 --- a/src/m365/spo/commands/storageentity/storageentity-set.spec.ts +++ b/src/m365/spo/commands/storageentity/storageentity-set.spec.ts @@ -266,7 +266,7 @@ describe(commands.STORAGEENTITY_SET, () => { it('rejects invalid SharePoint Online URL', async () => { const url = 'http://contoso'; const actual = await command.validate({ options: { appCatalogUrl: url, key: 'prop', value: 'val' } }, commandInfo); - assert.strictEqual(actual, `${url} is not a valid SharePoint Online site URL`); + assert.strictEqual(actual, `'${url}' is not a valid SharePoint Online site URL.`); }); it('handles promise rejection', async () => { diff --git a/src/utils/validation.ts b/src/utils/validation.ts index afe9e0c5c6b..11a7a5ce4b0 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -352,12 +352,12 @@ export const validation = { }, isValidSharePointUrl(url: string): boolean | string { - if (!url) { - return false; + if (typeof url !== 'string') { + return 'SharePoint Online site URL must be a string.'; } if (url.indexOf('https://') !== 0) { - return `${url} is not a valid SharePoint Online site URL`; + return `'${url}' is not a valid SharePoint Online site URL.`; } else { return true;