mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 00:53:18 +00:00
Add better input validation to the wiki grabber.
Some errors were silently ignored and thus input was silently lost.
This commit is contained in:
parent
2f4d95d63b
commit
0691d83ddd
@ -311,11 +311,36 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def validate_table(table):
|
||||||
|
"""Validates a table.
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# There is no escape yet, probably will be the @ character
|
||||||
|
regex = '[^\\s]\$[^$]'
|
||||||
|
invalid_record_terminator = re.compile(regex, re.VERBOSE).findall(table)
|
||||||
|
|
||||||
|
if len(invalid_field_separators) or len(invalid_record_terminator):
|
||||||
|
result = "Found %i invalid field separators " % (len(invalid_field_separators))
|
||||||
|
result += "and %i invalid record separators " % (len(invalid_record_terminator))
|
||||||
|
result += "in:\n%s\n\n" % (table)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def create_table(table):
|
def create_table(table):
|
||||||
"""Wrapper for creating tables."""
|
"""Wrapper for creating tables."""
|
||||||
|
|
||||||
type = table.group(1)
|
type = table.group(1)
|
||||||
|
|
||||||
|
errors = validate_table(table.group(2))
|
||||||
|
if errors:
|
||||||
|
sys.stderr.write(errors)
|
||||||
|
|
||||||
functions = {
|
functions = {
|
||||||
"config": create_config_table,
|
"config": create_config_table,
|
||||||
"formula": create_formula_table,
|
"formula": create_formula_table,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user