Improve the wiki grabber validation.

Also add escapes for & and $ in a table and use it at one place.
This commit is contained in:
Mark de Wever 2011-04-16 09:07:19 +00:00
parent 95f3637126
commit ac63238411
2 changed files with 14 additions and 7 deletions

View file

@ -348,7 +348,7 @@ const std::string& tgui_definition::read(const config& cfg)
* has_helptip_message & tstring & &
* The string used to append the tooltip
* if there is also a helptip. The WML
* variable $hotkey can be used to get show
* variable @$hotkey can be used to get show
* the name of the hotkey for the help. $
* @end{table}
*/

View file

@ -150,10 +150,14 @@ if __name__ == "__main__":
Replaces the following:
- An end of line and its surrounding whitespace to a single space.
- @$ -> $
- @& -> &
- @* -> \n* needed in a list.
- @- -> \n needed to add text after a list.
"""
data = re.sub(r'\s*\n\s*', ' ', data)
data = re.sub(r'@\$', '$', data)
data = re.sub(r'@&', '&', data)
data = re.sub(r'@\*', "\n*", data)
data = re.sub(r'@\-', "\n", data)
return data
@ -368,13 +372,16 @@ if __name__ == "__main__":
At the moments tests for whitespace around separators."""
# There is no escape yet, probably will be the @ character
regex = '[^\\s]&[^\\s]'
invalid_field_separators = re.compile(regex, re.VERBOSE).findall(table)
regex = '((?<![@\s])&)|([^@]&(?!\s))'
regex = re.compile(regex)
invalid_field_separators = regex.findall(table)
# There is no escape yet, probably will be the @ character
regex = '[^\\s]\$[^$]'
invalid_record_terminator = re.compile(regex, re.VERBOSE).findall(table)
# Not the last test should actually be (\$(?![\s\Z]) but that fails as
# work-around add a space to the input so when it would match the end
# of the string it now matches the added space.
regex = '((?<![@\s])\$)|([^@]\$(?!\s))'
regex = re.compile(regex)
invalid_record_terminator = regex.findall(table + ' ')
if len(invalid_field_separators) or len(invalid_record_terminator):
result = "Found %i invalid field separators " % (len(invalid_field_separators))