Page MenuHomePhabricator

Selser newline dirty diff potentially caused by a regexp backtracking failure
Open, LowPublic

Description

First things first. https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/551278 would be very useful in reproducing the bug / investigating it.

Consider this snippet extracted from https://fr.wikipedia.org/w/index.php?title=Liste_de_r%C3%A9pliques_de_la_grotte_de_Lourdes&action=edit&section=192

foo
<!--
{{Autres projets|commons=Category:Lourdes Grottoes in Germany|commons titre=Grottes en Allemagne}}
{{Autres projets|commons=Category:Lourdes Grottoes in Argentina|commons titre=Grottes en Argentine}}
{{Autres projets|commons=Category:Lourdes Grottoes in Austria|commons titre=Grottes en Autriche}}
{{Autres projets|commons=Category:Lourdes Grottoes in Belgium|commons titre=Grottes en Belgique}}
{{Autres projets|commons=Category:Lourdes Grottoes in Brasil|commons titre=Grottes au Brésil}}
{{Autres projets|commons=Category:Lourdes Grottoes in Canada|commons titre=Grottes au Canada}}
{{Autres projets|commons=Category:Lourdes Grottoes in Chili|commons titre=Grottes au Chili}}
{{Autres projets|commons=Category:Lourdes Grottoes in China|commons titre=Grottes en Chine}}
{{Autres projets|commons=Category:Lourdes Grottoes in Croatia|commons titre=Grottes en Croatie}}
{{Autres projets|commons=Category:Lourdes Grottoes in Spain|commons titre=Grottes en Espagne}}
{{Autres projets|commons=Category:Lourdes Grottoes in the United States|commons titre=Grottes aux États-Unis}}
{{Autres projets|commons=Category:Lourdes Grottoes in France by department|commons titre=Grottes en France}}
{{Autres projets|commons=Category:Lourdes Grottoes in Gibraltar|commons titre=Grottes à Gibraltar}}
{{Autres projets|commons=Category:Lourdes Grottoes in Hungary|commons titre=Grottes en Hongrie}}
{{Autres projets|commons=Category:Lourdes Grottoes in India|commons titre=Grottes en Inde}}
{{Autres projets|commons=Category:Lourdes Grottoes in Ireland|commons titre=Grottes en Irlande}}
{{Autres projets|commons=Category:Lourdes Grottoes in Lithuania|commons titre=Grottes en Lithuanie}}
{{Autres projets|commons=Category:Lourdes Grottoes in Luxembourg|commons titre=Grottes au Luxembourg}}
{{Autres projets|commons=Category:Lourdes Grottoes in Malta|commons titre=Grottes à Malte}}
{{Autres projets|commons=Category:Lourdes Grottoes in the Netherlands|commons titre=Grottes aux Pays-Bas}}
{{Autres projets|commons=Category:Lourdes Grottoes in the Philippines|commons titre=Grottes aux Philippines}}
{{Autres projets|commons=Category:Lourdes Grottoes in Poland|commons titre=Grottes en Pologne}}
{{Autres projets|commons=Category:Lourdes Grottoes in Puerto Rico|commons titre=Grottes à Porto-Rico}}
{{Autres projets|commons=Category:Lourdes Grottoes in the Czech Republic|commons titre=Grottes en République Tchèque}}
{{Autres projets|commons=Category:Lourdes Grottoes in the United Kingdom|commons titre=Grottes au Royaume-Uni}}
{{Autres projets|commons=Category:Lourdes Grottoes in Slovakia|commons titre=Grottes en Slovaquie}}
{{Autres projets|commons=Category:Lourdes Grottoes in Switzerland|commons titre=Grottes en Suisse}}
{{Autres projets|commons=Category:Lourdes Grottoes in Uruguay|commons titre=Grottes en Uruguay}}
-->
* bar

This is effectively a paragraph and a list with a comment between them. The normalized form would insert a newline before the list, but selser should preserve the original form without the additional newline. The bug is that it turns out that selser is ignoring the separator found in the original source because it considers it an invalid separator (WTSUtils::isValidSep check fails).

Now, here is the fun part. Try progressively reducing the size of the test case by deleting the comment lines or just gradually shortening the size of the comment. You will find that at some point, the selser diff vanishes and you can probably find the threshold at which the test changes from success to failure (or vice versa). That indicated to me that this is potentially some regexp backtracking issue that causes the isValidSep check to return false which in turn causes the selser failure.

This is a narrow edge case bug and not worth expending a lot of energy on at this point.