Skip to content

Commit

Permalink
Fix ½ifdefempty{}
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 28, 2018
1 parent 1707853 commit f69cfc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def setUp(self):
'false': False,
'non_empty_string': u'test',
'none': None,
'only_whitespaces': u' \t\n',
}

def parseEqual(self, a, b):
Expand All @@ -231,14 +232,19 @@ def test_non_empty_string(self):
self.parseEqual(u'%ifdefempty{non_empty_string,trueval,falseval}',
u'falseval')

# nonexistent
def test_nonexistent(self):
self.parseEqual(u'%ifdefempty{nonexistent,trueval,falseval}',
u'trueval')

# none
def test_none(self):
self.parseEqual(u'%ifdefempty{none,trueval}', u'trueval')

# nonexistent
def test_nonexistent(self):
self.parseEqual(u'%ifdefempty{nonexistent,trueval,falseval}',
u'falseval')
def test_only_whitespaces(self):
self.parseEqual(u'%ifdefempty{only_whitespaces,trueval,falseval}',
u'trueval')


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion tmep/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import division, absolute_import, print_function

import time
import re
import textwrap
from unidecode import unidecode

Expand Down Expand Up @@ -170,7 +171,9 @@ def tmpl_ifdefempty(self, field, trueval=u'', falseval=u''):
:param falseval: The string if the condition is false
:return: The string, based on condition
"""
if field in self.values and not self.values[field]:
if not field in self.values or \
(field in self.values and not self.values[field]) or \
re.search(r'^\s*$', self.values[field]):
return trueval
else:
return falseval
Expand Down

0 comments on commit f69cfc2

Please sign in to comment.