Skip to content

Commit

Permalink
Placeables: Skip non-placeholders with whitespace
Browse files Browse the repository at this point in the history
This fix prevents from detecting strings like "% s" to be format placeholders.

Fixes translate#3368.
  • Loading branch information
unho committed Mar 30, 2016
1 parent 9a6b99c commit 180c489
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion translate/storage/placeables/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class FormattingPlaceable(Ph):
regex = re.compile(r"""
% # introduction
(\d+\$)? # selection of non-next variable (reordering)
[\-\+0 \#'I]? # optional flag
[\-\+0\#'I]? # optional flag
((\d+)|[*])? # field width
(\.\d+)? # precision
[hlI]? # length
Expand Down
5 changes: 4 additions & 1 deletion translate/storage/placeables/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def test_placeable_formatting():
assert fp.parse(u'There were %d %s')[3] == fp([u'%s'])
assert fp.parse(u'%1$s was kicked by %2$s')[0] == fp([u'%1$s'])
assert fp.parse(u'There were %Id cows')[1] == fp([u'%Id'])
assert fp.parse(u'There were % d cows')[1] == fp([u'% d'])

# Skip placeholders with whitespace.
assert fp.parse(u'There were % d cows') is None

# only a real space is allowed as formatting flag
assert fp.parse(u'There were %\u00a0d cows') is None
assert fp.parse(u"There were %'f cows")[1] == fp([u"%'f"])
Expand Down

0 comments on commit 180c489

Please sign in to comment.