Author: mordante
Date: Thu Apr 14 20:39:21 2011
New Revision: 49195

URL: http://svn.gna.org/viewcvs/wesnoth?rev=49195&view=rev
Log:
Add better input validation to the wiki grabber.

Some errors were silently ignored and thus input was silently lost.

Modified:
    trunk/utils/wiki_grabber.py

Modified: trunk/utils/wiki_grabber.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/wiki_grabber.py?rev=49195&r1=49194&r2=49195&view=diff
==============================================================================
--- trunk/utils/wiki_grabber.py (original)
+++ trunk/utils/wiki_grabber.py Thu Apr 14 20:39:21 2011
@@ -310,11 +310,36 @@
         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,


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to