Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#807 | making sure encoding/decoding handles…
Browse files Browse the repository at this point in the history
… + and spaces separately
  • Loading branch information
snyaggarwal committed Jun 17, 2021
1 parent 8d4a197 commit 296cb60
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/common/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class EncodedDecodedCharField(CharField):
def to_internal_value(self, data):
string = super().to_internal_value(data)
return string if is_url_encoded_string(string) else encode_string(string)
return string if is_url_encoded_string(string) else encode_string(string, safe=' ')

def to_representation(self, value):
string = super().to_representation(value)
Expand Down
6 changes: 3 additions & 3 deletions core/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def is_csv_file(file=None, name=None):


def is_url_encoded_string(string, lower=True):
encoded_string = encode_string(decode_string(string))
encoded_string = encode_string(decode_string(string), safe=' ')

if lower:
return string.lower() == encoded_string.lower()
Expand All @@ -612,8 +612,8 @@ def is_url_encoded_string(string, lower=True):


def decode_string(string):
return parse.unquote(string)
return parse.unquote_plus(string)


def encode_string(string, **kwargs):
return parse.quote_plus(string, **kwargs)
return parse.quote(string, **kwargs)
2 changes: 1 addition & 1 deletion core/concepts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
PERSIST_CLONE_ERROR = 'An error occurred while saving new concept version.'
COULD_NOT_FIND_CONCEPT_TO_UPDATE = 'Could not find concept to update'
PARENT_VERSION_NOT_LATEST_CANNOT_UPDATE_CONCEPT = 'Parent version is not the latest. Cannot update concept.'
CONCEPT_PATTERN = r'[a-zA-Z0-9\-\.\_\@\+\%]+'
CONCEPT_PATTERN = r'[a-zA-Z0-9\-\.\_\@\+\%\s]+'
CONCEPT_REGEX = re.compile(r'^' + CONCEPT_PATTERN + '$')
20 changes: 20 additions & 0 deletions core/concepts/migrations/0011_auto_20210617_1229.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.1.9 on 2021-06-17 12:29

import django.core.validators
from django.db import migrations, models
import re


class Migration(migrations.Migration):

dependencies = [
('concepts', '0010_auto_20210521_0543'),
]

operations = [
migrations.AlterField(
model_name='concept',
name='mnemonic',
field=models.CharField(db_index=True, max_length=255, validators=[django.core.validators.RegexValidator(regex=re.compile('^[a-zA-Z0-9\\-\\.\\_\\@\\+\\% ]+$'))]),
),
]
20 changes: 20 additions & 0 deletions core/concepts/migrations/0012_auto_20210617_1231.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.1.9 on 2021-06-17 12:31

import django.core.validators
from django.db import migrations, models
import re


class Migration(migrations.Migration):

dependencies = [
('concepts', '0011_auto_20210617_1229'),
]

operations = [
migrations.AlterField(
model_name='concept',
name='mnemonic',
field=models.CharField(db_index=True, max_length=255, validators=[django.core.validators.RegexValidator(regex=re.compile('^[a-zA-Z0-9\\-\\.\\_\\@\\+\\%\\s]+$'))]),
),
]

0 comments on commit 296cb60

Please sign in to comment.