Skip to content

Commit

Permalink
fix: Custom parameters validation (#412)
Browse files Browse the repository at this point in the history
* fix: Custom parameters validation

* feat: Update version and changelog
  • Loading branch information
kuipumu authored Nov 20, 2023
1 parent 07a8c26 commit 62e2a79
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Please See the `releases tab <https://github.com/openedx/xblock-lti-consumer/rel
Unreleased
~~~~~~~~~~

9.8.1 - 2023-11-17
------------------
* Fix custom_parameters xblock field validation.

9.7.0 - 2023-10-23
------------------
* Added LTI 1.3 reusable configuration compatibility.
Expand Down
2 changes: 1 addition & 1 deletion lti_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .apps import LTIConsumerApp
from .lti_xblock import LtiConsumerXBlock

__version__ = '9.8.0'
__version__ = '9.8.1'
5 changes: 1 addition & 4 deletions lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@
'instructor': 'Instructor',
}
CUSTOM_PARAMETER_SEPARATOR = '='
# Allow a key-pair key and value to contain any character except "=".
CUSTOM_PARAMETER_REGEX = re.compile(
rf'^([^{CUSTOM_PARAMETER_SEPARATOR}]+{CUSTOM_PARAMETER_SEPARATOR}[^{CUSTOM_PARAMETER_SEPARATOR}]+)$',
)
CUSTOM_PARAMETER_REGEX = re.compile(rf'^(.+{CUSTOM_PARAMETER_SEPARATOR}.+)$')
# Catch a value enclosed by ${}, the value enclosed can contain any charater except "=".
CUSTOM_PARAMETER_TEMPLATE_REGEX = re.compile(r'^(\${[^%s]+})$' % CUSTOM_PARAMETER_SEPARATOR)

Expand Down
6 changes: 3 additions & 3 deletions lti_consumer/tests/unit/test_lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def test_context_id(self):
self.assertEqual(self.xblock.context_id, str(self.xblock.scope_ids.usage_id.context_key))

@ddt.data(
['x=y'], [' x x = y y '], ['x= '], [' =y'], [' = '],
['x=y', ' x x = y y ', 'x= ', ' =y', ' = '],
['x=y'], [' x x = y y '], ['x= '], [' =y'], [' = '], [' x = = y = z '],
['x=y', ' x x = y y ', 'x= ', ' =y', ' = ', ' x = = y = z '],
)
def test_validate_with_valid_custom_parameters(self, custom_parameters):
"""
Expand All @@ -167,7 +167,7 @@ def test_validate_with_empty_custom_parameters(self, add_mock, mock_validation_m
mock_validation_message('error', 'Custom Parameters must be a list'),
)

@ddt.data(['x'], ['x='], ['=y'], ['x==y'], ['x', 'x=', '=y', 'x==y'])
@ddt.data(['x'], ['x='], ['=y'], ['x', 'x=', '=y'])
@patch('lti_consumer.lti_xblock.ValidationMessage')
@patch.object(Validation, 'add')
def test_validate_with_invalid_custom_parameters(self, custom_parameters, add_mock, mock_validation_message):
Expand Down

0 comments on commit 62e2a79

Please sign in to comment.