Skip to content

Commit

Permalink
Fix: Parse whitespace in query parameters (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElinorW authored Mar 31, 2022
1 parent a2db247 commit ce6a060
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/app/utils/sample-url-generation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ describe('Sample Url Generation', () => {
it('destructures sample url with % sign', () => {
const name = 'DiegoS%40m365x214355.onmicrosoft.com';
const search = `?$select=displayName,mail&$filter=mail eq '${name}'`;
const parsedSearch = `?$select=displayName,mail&$filter=mail+eq+'${name}'`;

const url = `https://graph.microsoft.com/v1.0/users${search}`;

const expectedUrl = {
requestUrl: 'users',
queryVersion: 'v1.0',
sampleUrl: url,
search
sampleUrl: `https://graph.microsoft.com/v1.0/users${parsedSearch}`,
search: parsedSearch
};

const parsedUrl = parseSampleUrl(url);
Expand Down Expand Up @@ -75,6 +77,23 @@ describe('Sample Url Generation', () => {
expect(parsedUrl).toEqual(expectedUrl);
});

it('replaces whitespace with + sign', () => {
const search = '?filter=displayName eq \'All Company\'';
const parsedSearch= '?filter=displayName+eq+\'All+Company\'';

const url = `https://graph.microsoft.com/v1.0/groups${search}`;

const expectedUrl = {
requestUrl: 'groups',
queryVersion: 'v1.0',
sampleUrl:`https://graph.microsoft.com/v1.0/groups${parsedSearch}` ,
search: parsedSearch
};

const parsedUrl = parseSampleUrl(url);
expect(parsedUrl).toEqual(expectedUrl);
});

});


Expand Down
4 changes: 2 additions & 2 deletions src/app/utils/sample-url-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function generateSearchParameters(url: string, search: string) {
}
}
}
return search;
return search.replace(/\s/g, '+');
}

function generateSampleUrl(
Expand All @@ -85,5 +85,5 @@ export function hasWhiteSpace(url: string): boolean {
const parts = url.split('?');
return parts.length > 1 ? whitespaceChars.some((char) => parts[0].trimStart().includes(char)) :
whitespaceChars.some((char) => parts[0].trim().includes(char));

}

0 comments on commit ce6a060

Please sign in to comment.