Skip to content

Commit

Permalink
wmliterator: fix unterminated loop in lua-strip
Browse files Browse the repository at this point in the history
An old add-on triggered a wmliterator crash with this comment:

    #>>>> !!!!! REMOVE THIS AFTER TEST !!!!! <<<<#

The traceback showed that the crash came from the lua-stripping
code, which interprets "<<" as the start of a lua string. But below
it is code to remove quoted strings, and it doesn't crash, even
though there are cases where authors forgot to close a quote.

Two key differences stood out in the otherwise similar second
code: only looking for the endquote string in the text after
beginquote, and testing that endquote was less than 0, not -1.

Changing both gets the loop to terminate. Making it search the
text only after "beginquote+2" means that ">>" will no longer
be found, giving endquote a value of -1. But -1 is not less than
-1, so that must be changed to " < 0" to close the loop.
  • Loading branch information
groggyd88 committed May 11, 2015
1 parent 44cf1d4 commit 8c5b0b2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions data/tools/wesnoth/wmliterator.py
Expand Up @@ -235,8 +235,8 @@ def parseElements(self, text):
# first remove any lua strings
beginquote = text.find('<<')
while beginquote >= 0:
endquote = text.find('>>')
if endquote < -1:
endquote = text.find('>>', beginquote+2)
if endquote < 0:
text = text[:beginquote]
beginquote = -1 #terminate loop
else:
Expand Down

0 comments on commit 8c5b0b2

Please sign in to comment.