From c644da3dccc4e3ecaa561fe73581c011f54f03cb Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Tue, 10 Oct 2023 11:17:28 -0400 Subject: [PATCH] fix: decodeURIComponent for locationId Squashed commit of the following: commit af4d469ef241a504112dceda2cb94bff24ba4a9c Author: Vu Nguyen Date: Wed Oct 4 11:27:58 2023 +0700 update test cases commit d0c28fb99bede979fbcc8f57036ecb8027996772 Merge: 1f4d50b 5492520 Author: vunguyen-dmt <34919039+vunguyen-dmt@users.noreply.github.com> Date: Wed Oct 4 11:22:24 2023 +0700 Merge branch 'openedx:master' into fix_location_id_error commit 1f4d50b36514a6e4e9e575b938bf93b81317a21c Merge: a280a35 eb73457 Author: Vu Nguyen 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 a280a350fcf595dd2011018d113467a9cd88cd61 Author: Vu Nguyen Date: Fri Jul 21 03:44:28 2023 +0700 fix: decodeURIComponent for locationId commit eb734574bd0daae0c2523904763a8d755baa31f3 Author: Vu Nguyen Date: Fri Jul 21 03:41:28 2023 +0700 update src/data/constants/app.test.js commit 513dd324a5adc7312ac92c30164e0120784acd4b Merge: e899846 78ada8c Author: vunguyen-dmt <34919039+vunguyen-dmt@users.noreply.github.com> Date: Wed Jul 19 16:12:14 2023 +0700 Merge branch 'master' into fix_location_id_error commit e8998461de8ba9cbbe00a1726ad6266bde5d5ef5 Author: Vu Nguyen Date: Thu Jun 8 10:29:45 2023 +0700 fix: decodeURIComponent for locationId --- src/data/constants/app.js | 2 +- src/data/constants/app.test.js | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/data/constants/app.js b/src/data/constants/app.js index 58e11be6..cd6236f7 100644 --- a/src/data/constants/app.js +++ b/src/data/constants/app.js @@ -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, ''); diff --git a/src/data/constants/app.test.js b/src/data/constants/app.test.js index b36a0e47..21908022 100644 --- a/src/data/constants/app.test.js +++ b/src/data/constants/app.test.js @@ -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; + }); }); });