Skip to content

Commit

Permalink
Adds throwing error when SP URL is empty. Closes #6012
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh7019 authored and milanholemans committed May 24, 2024
1 parent 8bc3ba9 commit 62874a2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/m365/spo/commands/folder/folder-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 62874a2

Please sign in to comment.