--- /dev/null
+.. change::
+ :tags: bug, mysql
+ :tickets: 13393
+
+ Improved the regular expression used to parse index ``COMMENT`` clauses
+ in MySQL ``SHOW CREATE TABLE`` reflection to use an unambiguous
+ single-quoted-string pattern; the previous pattern was theoretically
+ subject to backtracking on malformed input, though such input is not
+ producible by MySQL itself. Fix courtesy of Javid Khan.
r"(?: +USING +(?P<using_post>\S+))?"
r"(?: +KEY_BLOCK_SIZE *[ =]? *(?P<keyblock>\S+))?"
r"(?: +WITH PARSER +(?P<parser>\S+))?"
- r"(?: +COMMENT +(?P<comment>(\x27\x27|\x27([^\x27])*?\x27)+))?"
+ r"(?: +COMMENT +(?P<comment>\x27(?:\x27\x27|[^\x27])*\x27))?"
r"(?: +/\*(?P<version_sql>.+)\*/ *)?"
r",?$" % quotes
)
eq_(m.group("type"), "PRIMARY")
eq_(m.group("columns"), "`id`")
+ @testing.combinations(
+ # 60 single quotes is a valid SQL string (29 '' pairs inside outer
+ # quotes); the previous ambiguous pattern backtracked on this input
+ (" KEY (`id`) COMMENT " + ("'" * 60), "'" * 60),
+ # odd quotes followed by a non-quote: uncloseable, should not match
+ (" KEY (`id`) COMMENT " + ("'" * 59) + "x", None),
+ argnames="line,expected_comment",
+ )
+ def test_key_reflection_comment_many_quotes(self, line, expected_comment):
+ regex = self.parser._re_key
+ m = regex.match(line)
+ eq_(
+ m.group("comment") if m is not None else None,
+ expected_comment,
+ )
+
def test_key_reflection_columns(self):
regex = self.parser._re_key
exprs = self.parser._re_keyexprs