insert rstrip() to fix wmllint-crashing assumption that unit files are using Unix newlines
In Linux, many 1.2 unit files would crash wmllint, with tracebacks pointing to the "assert male/female_end != -1" line. Male/female_end's value is set to -1, and when it does not meet the condition for converting to i (line index position), the assert statement fails. The "assert male_end" error crashes files with gender=male, or no gender= key (thus defaulting to male). The "assert female_end" error is the female counterpart, and also covers units with both genders. I found that after commenting out these assert statements, wmllint no longer barfed on those files. Studying the problem for this commit, however, I saw that "endswith()" included a newline. Could it simply be choking on DOS carriage returns? Doing a dryrun in Windows, which defaults to universal newlines support, I did not get the crashes. Change to binary mode, the crashes returned. Insert rstrip() and delete the newlines, and the crashes stop!
This commit is contained in:
parent
caf6587318
commit
fa43e3688b
1 changed files with 2 additions and 2 deletions
|
@ -1174,7 +1174,7 @@ def hack_syntax(filename, lines):
|
|||
if female_attacks:
|
||||
female_end = -1
|
||||
for i in range(len(lines)):
|
||||
if lines[i].endswith("[/female]\n"):
|
||||
if lines[i].rstrip().endswith("[/female]"):
|
||||
female_end = i
|
||||
break
|
||||
assert female_end != -1
|
||||
|
@ -1187,7 +1187,7 @@ def hack_syntax(filename, lines):
|
|||
for i in range(len(lines)):
|
||||
# Male attacks go either before the [female] tag or just
|
||||
# before the closing [/unit]
|
||||
if lines[i].endswith("[/unit]\n") or lines[i].endswith("[female]\n"):
|
||||
if lines[i].rstrip().endswith("[/unit]") or lines[i].rstrip().endswith("[female]"):
|
||||
male_end = i
|
||||
break
|
||||
assert male_end != -1
|
||||
|
|
Loading…
Add table
Reference in a new issue