Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unidecode to handle unicode characters in constant names #1080

Merged
merged 3 commits into from Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion graphene/utils/str_converters.py
@@ -1,4 +1,5 @@
import re
from unidecode import unidecode


# Adapted from this response in Stackoverflow
Expand All @@ -18,4 +19,4 @@ def to_snake_case(name):


def to_const(string):
return re.sub(r"[\W|^]+", "_", string).upper() # noqa
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()
4 changes: 4 additions & 0 deletions graphene/utils/tests/test_str_converters.py
Expand Up @@ -21,3 +21,7 @@ def test_camel_case():

def test_to_const():
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"


def test_to_const_unicode():
assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -86,6 +86,7 @@ def run_tests(self):
"graphql-core>=3.0.0,<4",
"graphql-relay>=3.0.0,<4",
"aniso8601>=6,<9",
"unidecode>=1.1.1,<2",
],
tests_require=tests_require,
extras_require={"test": tests_require, "dev": dev_requires},
Expand Down