Page MenuHomePhabricator

Previewing an invalid content edit (JSON) results in a LogicException
Closed, DuplicatePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Create a page, change its content model to JSON.
  • Change the contents to be invalid, for example {"a":"b}.
  • Hit the preview button.
  • Exception's thrown.

What happens?: A LogicException is thrown due to the JSON content handler emitting no text for invalid data.

/wiki/Data:Test?action=submit LogicException: This ParserOutput contains no text!

Backtrace:

from /var/www/wiki/includes/parser/ParserOutput.php(363)
#0 /var/www/wiki/includes/parser/ParserOutput.php(412): ParserOutput->getRawText()
#1 /var/www/wiki/includes/EditPage.php(4538): ParserOutput->getText()
#2 /var/www/wiki/includes/EditPage.php(4434): EditPage->doPreviewParse()
#3 /var/www/wiki/includes/EditPage.php(3143): EditPage->getPreviewText()
#4 /var/www/wiki/includes/EditPage.php(778): EditPage->showEditForm()
#5 /var/www/wiki/includes/actions/EditAction.php(73): EditPage->edit()
#6 /var/www/wiki/includes/actions/SubmitAction.php(38): EditAction->show()
#7 /var/www/wiki/includes/MediaWiki.php(542): SubmitAction->show()
#8 /var/www/wiki/includes/MediaWiki.php(322): MediaWiki->performAction()
#9 /var/www/wiki/includes/MediaWiki.php(904): MediaWiki->performRequest()
#10 /var/www/wiki/includes/MediaWiki.php(562): MediaWiki->main()
#11 /var/www/wiki/index.php(50): MediaWiki->run()
#12 /var/www/wiki/index.php(46): wfIndexMain()
#13 {main}

What should have happened instead?: Refuse the preview and display the edit form along with a validation error again.

Software version (skip for WMF-hosted wikis like Wikipedia): 1.39.0

Event Timeline

Alex44019 renamed this task from Previewing an invalid JSON edit results in a LogicException to Previewing an invalid content edit (JSON) results in a LogicException.Dec 23 2022, 5:08 AM

I can replicate this on 1.39.0, and it looks like https://gerrit.wikimedia.org/r/c/mediawiki/core/+/852915 (see T321319) might need to be backported to fix this — issue isn't present on the current MediaWiki master