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
1 changed files with 25 additions and 0 deletions
|
@ -310,12 +310,37 @@ if __name__ == "__main__":
|
|||
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):
|
||||
"""Wrapper for creating tables."""
|
||||
|
||||
type = table.group(1)
|
||||
|
||||
errors = validate_table(table.group(2))
|
||||
if errors:
|
||||
sys.stderr.write(errors)
|
||||
|
||||
functions = {
|
||||
"config": create_config_table,
|
||||
"formula": create_formula_table,
|
||||
|
|
Loading…
Add table
Reference in a new issue