Skip to content

Commit

Permalink
Fix: Selectively disable invalid url warning (#1484)
Browse files Browse the repository at this point in the history
* selectively disable white space error

* adjust tests
  • Loading branch information
Onokaev authored Feb 24, 2022
1 parent 8704131 commit eca50b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/app/utils/sample-url-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export function removeExtraSlashesFromUrl(url: string): string {
}

export function hasWhiteSpace(url: string): boolean {
const parts = url.split('?');
const whitespaceChars = [' ', '\t', '\n', '%20'];
return whitespaceChars.some((char) => parts[0].includes(char));
const parts = url.split('?');
return parts.length > 1 ? whitespaceChars.some((char) => parts[0].trimStart().includes(char)) :
whitespaceChars.some((char) => parts[0].trim().includes(char));

}
4 changes: 2 additions & 2 deletions src/tests/utils/sample-url-generation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ describe('Sample Url Generation', () => {

describe('hasWhiteSpaces should', () => {
const invalidUrls = [
{url: ' https://graph.microsoft.com/v1.0/me', output: true},
{url: ' https://graph.microsoft.com/v1.0/me', output: false},
{url: 'https: //graph.microsoft.com/v1.0/me', output: true},
{url: 'https://%20graph.microsoft.com/v1.0/me', output: true},
{url: 'https://graph.microsoft.com/ v1.0/me', output: true},
{url: 'https://graph.microsoft.com/v1.0/ me', output: true},
{url:
'https://graph.microsoft.com/v1.0/me/contacts?$filter=emailAddresses/any(a:a/address eq \'[email protected]\')',
output: false},
{url: 'https://graph.microsoft.com/v1.0/me ', output: true}
{url: 'https://graph.microsoft.com/v1.0/me ', output: false}
];
invalidUrls.forEach(invalidUrl => {
it(`validate whitespaces in the url: ${invalidUrl.url}`, () => {
Expand Down

0 comments on commit eca50b5

Please sign in to comment.