Page MenuHomePhabricator

Header regex does not work if there is comment ending before the heading
Open, LowPublic

Description

On some pages Pywikibot freezes when doing removeEmptySections. It happens time to time:

Exception in thread Put-Thread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pavel/pywikibot/pywikibot/__init__.py", line 1404, in async_manager
    request(*args, **kwargs)
  File "/home/pavel/pywikibot/pywikibot/page.py", line 109, in handle
    func(self, *args, **kwargs)
  File "/home/pavel/pywikibot/pywikibot/page.py", line 1292, in _save
    summary = self._cosmetic_changes_hook(summary)
  File "/home/pavel/pywikibot/pywikibot/page.py", line 1338, in _cosmetic_changes_hook
    self.text = cc_toolkit.change(old)
  File "/home/pavel/pywikibot/pywikibot/cosmetic_changes.py", line 302, in change
    new_text = self._change(text)
  File "/home/pavel/pywikibot/pywikibot/cosmetic_changes.py", line 296, in _change
    text = self.safe_execute(method, text)
  File "/home/pavel/pywikibot/pywikibot/cosmetic_changes.py", line 283, in safe_execute
    result = method(text)
  File "/home/pavel/pywikibot/pywikibot/cosmetic_changes.py", line 778, in removeEmptySections
    current_heading = sections[i][0]
IndexError: list index out of range

This is caused by the header regex in textlib, which can not work with line like this:

text

<!-- comment
-->== Heading ==
text

If we strip comments, it works, if we do not, it doesn't work. Therefore errors like this can happen. MediaWiki can parse heading like this correctly, therefore we should too.

Details

Event Timeline

Dvorapa renamed this task from removeEmptySections freezes on some pages to Header regex does not work if there is comment ending before the heading.Nov 16 2018, 4:43 PM
Dvorapa updated the task description. (Show Details)

Btw, @Dvorapa, is header like below is accepted also in Mediawiki?

=<!-- comment-->= Heading ==

I'm a bit doubtful about it since the current header regex catches that

I don't know, but it is easy to try:

Snímek z 2018-11-17 18-00-33.png (1,299×741 px, 103 KB)

Snímek z 2018-11-17 18-00-25.png (1,299×741 px, 129 KB)

No.

No.

I think it's accepted as heading 1, but the text is = Babovky =, am I right?

No.

I think it's accepted as heading 1, but the text is = Babovky =, am I right?

I added: =<!-- B -->= Bábovky ==
Parser outputted: first level heading made by outer "=". Therefore it works, but partially (not as one would expect second level heading)

Xqt triaged this task as Medium priority.Dec 10 2018, 1:07 PM

Every second article today fails to save with cc on for me. My head explodes in a minute! :D

Also breaks on

== Heading ==<!--== Another heading ==
-->

Change 489679 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [bugfix] Fix header regex beginning with a comment

https://gerrit.wikimedia.org/r/489679

Change 489679 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix header regex beginning with a comment

https://gerrit.wikimedia.org/r/489679

Xqt claimed this task.
Dvorapa reopened this task as Open.EditedFeb 11 2019, 3:37 PM
Dvorapa lowered the priority of this task from Medium to Low.

Still one broken unhandled rare case

Dvorapa removed Xqt as the assignee of this task.Feb 11 2019, 3:37 PM
Dvorapa added a subscriber: Xqt.

Also cosmetic-changes should fail silently and not interrupt the edit and freeze the scripts like replace.py, add_text.py etc...