Skip to content

Commit

Permalink
Merge pull request #141 from andriykohut/fix-pascal-case
Browse files Browse the repository at this point in the history
Fix PascalCase prepending underscores
  • Loading branch information
vbabiy committed Feb 18, 2024
2 parents 6a3a143 + 6e7b49c commit 52209e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion djangorestframework_camel_case/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_underscoreize_re(options):

def camel_to_underscore(name, **options):
underscoreize_re = get_underscoreize_re(options)
return underscoreize_re.sub(r"\1_\2", name).lower()
return underscoreize_re.sub(r"\1_\2", name).lower().lstrip("_")


def _get_iterable(data):
Expand Down
12 changes: 12 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def test_camel_to_under_keys(self):
"optionS1": 13,
"optionS10": 14,
"UPPERCASE": 15,
"PascalCase": 16,
"Pascal10Case": 17,
}
output = {
"two_word": 1,
Expand All @@ -125,6 +127,8 @@ def test_camel_to_under_keys(self):
"option_s_1": 13,
"option_s_10": 14,
"uppercase": 15,
"pascal_case": 16,
"pascal_10_case": 17,
}
self.assertEqual(underscoreize(data), output)

Expand Down Expand Up @@ -239,6 +243,8 @@ def test_camel_to_under_keys(self):
"optionS1": 13,
"optionS10": 14,
"UPPERCASE": 15,
"PascalCase": 16,
"Pascal10Case": 17,
}
query_dict.update(data)

Expand All @@ -260,6 +266,8 @@ def test_camel_to_under_keys(self):
"option_s_1": 13,
"option_s_10": 14,
"uppercase": 15,
"pascal_case": 16,
"pascal_10_case": 17,
}
output_query.update(output)
self.assertEqual(underscoreize(query_dict), output_query)
Expand All @@ -285,6 +293,8 @@ def test_camel_case_to_underscore_query_params(self):
"optionS1": "13",
"optionS10": "14",
"UPPERCASE": "15",
"PascalCase": "16",
"Pascal10Case": "17",
}
query_dict.update(data)

Expand All @@ -306,6 +316,8 @@ def test_camel_case_to_underscore_query_params(self):
"option_s_1": "13",
"option_s_10": "14",
"uppercase": "15",
"pascal_case": "16",
"pascal_10_case": "17",
}
output_query.update(output)
request = RequestFactory().get("/", query_dict)
Expand Down

0 comments on commit 52209e1

Please sign in to comment.