Skip to content

Commit

Permalink
fix: falseable empty array being mishandled
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Aug 4, 2024
1 parent 60c957f commit 3a4c961
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = 'normalize_json'
version = '0.0.12'
version = '0.0.14'
authors = [
{ name = 'João Gabriel Santos', email = '[email protected]' }
]
Expand Down
11 changes: 9 additions & 2 deletions src/normalize_json/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import re
import dateutil.parser as dateparser
import unicodedata

T = typing.TypeVar('T')

Expand All @@ -19,7 +20,8 @@
'strict',
'reverse',
'default_null',
'enforce'
'enforce',
'normalize_unicode'
]

AcceptedType = typing.Literal[
Expand Down Expand Up @@ -127,6 +129,9 @@ def handle_modifiers(node: Node, mapped_name: str, modifiers: list[Modifier], ol
else:
raise ValueError('value for %s wasnt provided' % mapped_name)

if 'normalize_unicode' in modifiers and isinstance(value, str):
value = unicodedata.normalize('NFKD', value)

if trim := node.get('trim_start'):
value = value[trim*-1:]

Expand Down Expand Up @@ -223,7 +228,9 @@ def translate(
if not node.get('map'):
value = translate(typing.cast(typing.Any, target), node, acc, modifiers, substitute=substitute)
else:
child: typing.Any = initial_value or target[original_name]
child: typing.Any = initial_value \
if initial_value or isinstance(initial_value, list) \
else target[original_name]
value = translate(child, node, acc, modifiers, (flat_obj, flat_obj_arr), substitute=substitute)
if node.get('array') and not isinstance(value, list):
value = [value]
Expand Down

0 comments on commit 3a4c961

Please sign in to comment.