Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Parse whitespace in query parameters #1555

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));

}