Skip to content

Commit

Permalink
fix: decodeURIComponent for locationId
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit af4d469
Author: Vu Nguyen <[email protected]>
Date:   Wed Oct 4 11:27:58 2023 +0700

    update test cases

commit d0c28fb
Merge: 1f4d50b 5492520
Author: vunguyen-dmt <[email protected]>
Date:   Wed Oct 4 11:22:24 2023 +0700

    Merge branch 'openedx:master' into fix_location_id_error

commit 1f4d50b
Merge: a280a35 eb73457
Author: Vu Nguyen <[email protected]>
Date:   Fri Jul 21 03:45:05 2023 +0700

    Merge branch 'fix_location_id_error' of https://github.com/vunguyen-dmt/frontend-app-ora-grading into fix_location_id_error

commit a280a35
Author: Vu Nguyen <[email protected]>
Date:   Fri Jul 21 03:44:28 2023 +0700

    fix: decodeURIComponent for locationId

commit eb73457
Author: Vu Nguyen <[email protected]>
Date:   Fri Jul 21 03:41:28 2023 +0700

    update src/data/constants/app.test.js

commit 513dd32
Merge: e899846 78ada8c
Author: vunguyen-dmt <[email protected]>
Date:   Wed Jul 19 16:12:14 2023 +0700

    Merge branch 'master' into fix_location_id_error

commit e899846
Author: Vu Nguyen <[email protected]>
Date:   Thu Jun 8 10:29:45 2023 +0700

    fix: decodeURIComponent for locationId
  • Loading branch information
leangseu-edx committed Oct 10, 2023
1 parent cc11ce0 commit c644da3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/data/constants/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConfig } from '@edx/frontend-platform';

export const routePath = () => `${getConfig().PUBLIC_PATH}:courseId`;
export const locationId = () => window.location.pathname.replace(getConfig().PUBLIC_PATH, '');
export const locationId = () => decodeURIComponent(window.location.pathname).replace(getConfig().PUBLIC_PATH, '');
29 changes: 24 additions & 5 deletions src/data/constants/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ describe('app constants', () => {
test('route path draws from public path and adds courseId', () => {
expect(constants.routePath()).toEqual(`${platform.PUBLIC_PATH}:courseId`);
});
test('locationId returns trimmed pathname', () => {
const old = window.location;
window.location = { pathName: `${platform.PUBLIC_PATH}somePath.jpg` };
expect(constants.locationId()).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
window.location = old;
describe('locationId', () => {
const domain = 'https://example.com';

test('returns trimmed pathname', () => {
const old = window.location;
Object.defineProperty(window, 'location', {
value: new URL(`${domain}${platform.PUBLIC_PATH}somePath.jpg`),
writable: true,
});
expect(constants.locationId()).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
window.location = old;
});
test('handle none-standard characters pathName', () => {
const old = window.location;
const noneStandardPath = `${platform.PUBLIC_PATH}ORG+%C4%90+2023`;
const expectedPath = `${platform.PUBLIC_PATH}ORG+Đ+2023`;
Object.defineProperty(window, 'location', {
value: new URL(`${domain}${noneStandardPath}`),
writable: true,
});
expect(noneStandardPath).not.toEqual(expectedPath);
expect(constants.locationId()).toEqual(expectedPath.replace(platform.PUBLIC_PATH, ''));
window.location = old;
});
});
});

0 comments on commit c644da3

Please sign in to comment.