From bc998c9f92d30147cd16be4713fb49516532fb48 Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Fri, 19 Jul 2024 17:46:25 +0300 Subject: [PATCH 1/2] Improve the sanitize_next_parameter method with handling new cases --- common/djangoapps/student/helpers.py | 20 ++++++++++++++++ .../djangoapps/student/tests/test_helpers.py | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index 4c2fcf7efd6..0dd0d1f10d5 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -714,7 +714,27 @@ def sanitize_next_parameter(next_param): return next_param if COURSE_URL_PATTERN.match(next_param): + # Sometimes the course id received with incorrect encoding/decoding, we need to + # replace it to the correct pattern: + # course-v1:test-sandbox PREP-CORE C -> course-v1:test-sandbox+PREP-CORE+C + # + # Note: We are not expect to have any spaces in course URL + + if ' ' in next_param: + next_param = next_param.replace(' ', '+') + elif '%20' in next_param: + next_param = next_param.replace('%20', '+') + sanitized_next_parameter = re.sub(r'\+', '%2B', next_param) + + log.info( + u"The course-like next parameter was detected '%(next_param)s'" + u" this will be replaced with sanitized version: '%(sanitized_next_parameter)s'", + { + "next_param": next_param, + "sanitized_next_parameter": sanitized_next_parameter, + } + ) return sanitized_next_parameter return next_param diff --git a/common/djangoapps/student/tests/test_helpers.py b/common/djangoapps/student/tests/test_helpers.py index 8231503c8a5..f069910296f 100644 --- a/common/djangoapps/student/tests/test_helpers.py +++ b/common/djangoapps/student/tests/test_helpers.py @@ -178,3 +178,27 @@ def test_sanitize_next_param(self): # Invalid pattern - keep the next_param as it is next_param = 'some/other/path' self.assertEqual(sanitize_next_parameter(next_param), next_param) + + # Invalid URL with space - replace the ' ' with '+' and encode it + expected_result = 'courses/course-v1:abc-sandbox%2BACC-PTF%2BC/course' + + next_param = 'courses/course-v1:abc-sandbox ACC-PTF C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) + + next_param = 'courses/course-v1:abc-sandbox ACC-PTF+C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) + + next_param = 'courses/course-v1:abc-sandbox+ACC-PTF C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) + + # Invalid URL with encoded space - replace the '%20' with '+' and encode it + expected_result = 'courses/course-v1:abc-sandbox%2BACC-PTF%2BC/course' + + next_param = 'courses/course-v1:abc-sandbox%20ACC-PTF%20C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) + + next_param = 'courses/course-v1:abc-sandbox%20ACC-PTF+C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) + + next_param = 'courses/course-v1:abc-sandbox+ACC-PTF%20C/course' + self.assertEqual(sanitize_next_parameter(next_param), expected_result) From 7b5c7c1210956f60f8188ac74548fb6afbdfa6aa Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Mon, 22 Jul 2024 11:26:57 +0300 Subject: [PATCH 2/2] Fix sync_prod_with_main workflow --- .github/workflows/sync_nutmeg_with_juniper.yml | 2 +- .github/workflows/sync_prod_with_main.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync_nutmeg_with_juniper.yml b/.github/workflows/sync_nutmeg_with_juniper.yml index f92283f378d..c1dbb1130b6 100644 --- a/.github/workflows/sync_nutmeg_with_juniper.yml +++ b/.github/workflows/sync_nutmeg_with_juniper.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: pull-request-action - uses: vsoch/pull-request-action@1.0.19 + uses: vsoch/pull-request-action@1.1.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_PREFIX: "main" diff --git a/.github/workflows/sync_prod_with_main.yml b/.github/workflows/sync_prod_with_main.yml index eab2bbcee3d..358f6072bf3 100644 --- a/.github/workflows/sync_prod_with_main.yml +++ b/.github/workflows/sync_prod_with_main.yml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest steps: - name: pull-request-action - uses: vsoch/pull-request-action@1.0.19 + uses: vsoch/pull-request-action@1.1.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_PREFIX: "main" PULL_REQUEST_BRANCH: "prod" PULL_REQUEST_TITLE: "Update from `main` (production)" - PULL_REQUEST_REVIEWERS: "xscrio amirtds bryanlandia" + PULL_REQUEST_REVIEWERS: "VladyslavTy daniilly"