Skip to content

Commit

Permalink
Merge pull request #1408 from appsembler/main
Browse files Browse the repository at this point in the history
Update from `main` (production)
  • Loading branch information
VladyslavTy authored Jul 22, 2024
2 parents 5609a73 + cd7be06 commit 00edcf9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sync_nutmeg_with_juniper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sync_prod_with_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 20 additions & 0 deletions common/djangoapps/student/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions common/djangoapps/student/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 00edcf9

Please sign in to comment.