# HG changeset patch # User Paul Boddie # Date 1493910712 -7200 # Node ID 077c49a4d6701f626f8fbe5d2f770ef8c7b7d220 # Parent 700dd2d1431543e9b5ca74a77223a02d48c88cfc Added some table attribute validation. diff -r 700dd2d14315 -r 077c49a4d670 moinformat/__init__.py --- a/moinformat/__init__.py Thu May 04 16:04:52 2017 +0200 +++ b/moinformat/__init__.py Thu May 04 17:11:52 2017 +0200 @@ -459,7 +459,35 @@ attrs = TableAttrs([]) parse_region_details(items, attrs, table_pattern_names) - cell.attrs = attrs + + # Test the validity of the attributes. + + last = None + + for node in attrs.nodes: + + # Text separator nodes must be whitespace. + + if isinstance(node, Text): + if node.s.strip(): + break + + # Named attributes must be preceded by space if not the first. + + elif last and not node.concise and not isinstance(last, Text): + break + + last = node + + # All nodes were valid: preserve the collection. + + else: + cell.attrs = attrs + return + + # Invalid nodes were found: serialise the attributes as text. + + cell.append_inline(Text(serialise(attrs))) def parse_table_row(items, region): diff -r 700dd2d14315 -r 077c49a4d670 tests/test12.txt --- a/tests/test12.txt Thu May 04 16:04:52 2017 +0200 +++ b/tests/test12.txt Thu May 04 17:11:52 2017 +0200 @@ -5,3 +5,6 @@ || Also not a table || Almost a table || ... || A table, trailing space || + +||<20%%name="value"> Bad separator || +||<20%xx-2> Strange attributes ||