Skip to content

Commit

Permalink
handler empty item of string-array
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasos Bakogiannis authored and kbairak committed May 10, 2016
1 parent 99b13ef commit bbf5a34
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions openformats/formats/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _compile_child(self, child):
elif child.tag == self.STRING_PLURAL:
self._compile_string_plural(child)

def _compile_string(self, child):
def _compile_string(self, child, string_array=False):
"""Handles child element that has the `string` and `item` tag.
It will compile the tag if matching string exists. Otherwise it will
Expand All @@ -430,6 +430,10 @@ def _compile_string(self, child):
self.transcriber.add(self.next_string.string)
self.transcriber.skip_until(child.content_end)
self.next_string = self._get_next_string()
elif string_array and not child.text:
# In the case of a string-array we don't want to skip an
# empty array element that was initially empty.
pass
else:
self._skip_tag(child)

Expand Down Expand Up @@ -460,7 +464,7 @@ def _compile_string_array(self, child):
if has_match:
# Compile found item nodes. Remove the rest.
for item_tag in item_itterator:
self._compile_string(item_tag)
self._compile_string(item_tag, string_array=True)
else:
# Remove the `string-array` tag
self._skip_tag(child)
Expand Down Expand Up @@ -510,7 +514,7 @@ def _should_compile(self, child):
:param child: The child to check if it should be compiled.
:returns: True if the child should be compiled else False.
"""
child_content = child.content and child.content.strip() or None
child_content = child.content and child.content.strip() or ''
return (
self.next_string is not None and
self.next_string.template_replacement == child_content
Expand Down

0 comments on commit bbf5a34

Please sign in to comment.