Last modified: 2013-04-22 16:17:07 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T29936, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27936 - preprocessor fail at parsing more than two back-to-back nested elements
preprocessor fail at parsing more than two back-to-back nested elements
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Normal normal (vote)
: 1.21.0 release
Assigned To: Dan Collins
http://de.wikipedia.org/wiki/Spezial:...
: newparser, patch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-08 16:31 UTC by Bergi
Modified: 2013-04-22 16:17 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
proposed patch (1.93 KB, patch)
2011-03-08 16:31 UTC, Bergi
Details
testcase (915 bytes, text/plain)
2011-03-09 10:23 UTC, Bergi
Details
expected testresult (3.63 KB, text/plain)
2011-03-09 10:23 UTC, Bergi
Details
proposed patch (2.09 KB, patch)
2011-03-09 10:25 UTC, Bergi
Details
Single unified patch against phase3 with code changes and (passing!) parser test (8.42 KB, patch)
2011-07-31 23:42 UTC, Dan Collins
Details
Updated patch against r104190 (12.53 KB, patch)
2011-11-24 20:55 UTC, Dan Collins
Details

Description Bergi 2011-03-08 16:31:22 UTC
Created attachment 8264 [details]
proposed patch

When there is a piece with lots of opening braces at the stack, which should get three or more elements, just the two topmost are recognised. The rest will be handled as $skippedBraces even when it would be enough to create an element.
This problem of course is very rare and and can be simply worked around by some whitspaces, but I guess this behavior is not intended.
I tried to write a patch, hoping not to create PHP syntax errors :-)
Comment 1 Antoine "hashar" Musso (WMF) 2011-03-08 16:32:28 UTC
adding some keywords
Comment 2 Bergi 2011-03-09 10:20:11 UTC
Comment on attachment 8264 [details]
proposed patch

>Index: Preprocessor_DOM.php
>===================================================================
>--- Preprocessor_DOM.php	(Revision 83528)
>+++ Preprocessor_DOM.php	(Arbeitskopie)
>@@ -611,18 +611,12 @@
> 					$piece->count -= $matchingCount;
> 					# do we still qualify for any callback with remaining count?
>-					$names = $rules[$piece->open]['names'];
>-					$skippedBraces = 0;
>-					$enclosingAccum =& $accum;
>-					while ( $piece->count ) {
>-						if ( array_key_exists( $piece->count, $names ) ) {
>-							$stack->push( $piece );
>-							$accum =& $stack->getAccum();
>-							break;
>-						}
>-						--$piece->count;
>-						$skippedBraces ++;
>-					}
>-					$enclosingAccum .= str_repeat( $piece->open, $skippedBraces );
>+					$min = $rules[$piece->open]['min'];
>+					if ( $piece->count >= $names->min ) {
>+						$stack->push( $piece );
>+						$accum =& $stack->getAccum();
>+					} else {
>+						$accum .= str_repeat( $piece->open, $piece->count );
>+ 				 	}
> 				}
> 				$flags = $stack->getFlags();
> 				extract( $flags );
>Index: Preprocessor_Hash.php
>===================================================================
>--- Preprocessor_Hash.php	(Revision 83528)
>+++ Preprocessor_Hash.php	(Arbeitskopie)
>@@ -624,18 +624,12 @@
> 					$piece->count -= $matchingCount;
> 					# do we still qualify for any callback with remaining count?
>-					$names = $rules[$piece->open]['names'];
>-					$skippedBraces = 0;
>-					$enclosingAccum =& $accum;
>-					while ( $piece->count ) {
>-						if ( array_key_exists( $piece->count, $names ) ) {
>-							$stack->push( $piece );
>-							$accum =& $stack->getAccum();
>-							break;
>-						}
>-						--$piece->count;
>-						$skippedBraces ++;
>-					}
>-					$enclosingAccum->addLiteral( str_repeat( $piece->open, $skippedBraces ) );
>+					$min = $rules[$piece->open]['min'];
>+					if ( $piece->count >= $min ) {
>+						$stack->push( $piece );
>+						$accum =& $stack->getAccum();
>+					} else {
>+						$accum .= str_repeat( $piece->open, $piece->count );
>+ 				 	}
> 				}
> 
> 				extract( $stack->getFlags() );
Comment 3 Bergi 2011-03-09 10:23:07 UTC
Created attachment 8273 [details]
testcase
Comment 4 Bergi 2011-03-09 10:23:43 UTC
Created attachment 8274 [details]
expected testresult
Comment 5 Bergi 2011-03-09 10:25:18 UTC
Created attachment 8275 [details]
proposed patch
Comment 6 Bergi 2011-03-09 10:28:35 UTC
Sorry, I didn't want to comment the patch, I tried to edit it. Forget comment 2 :-)
preprocessor-prasertests uploaded.
Comment 7 DieBuche 2011-04-15 09:55:44 UTC
Could you maybe write a parserTest (phase3/tests/parser/parserTests.txt); I can't seem to understand the testcase (what is the input, what is result, what is the expected result)
Comment 8 Bergi 2011-04-21 12:54:50 UTC
I'm sorry, I don't understand the syntax of these parser tests, and http://www.mediawiki.org/wiki/Parser_tests is still a redlink.
It should be a preprocessor test, like those in phase3/tests/parser/preprocess/.

The problem is, when there are lots of opening braces, their closing does not work for more than two stack elements. You can see this at "{{{{{{ }} }} }}", which renders to "{{<tpl><tpl> </tpl> </tpl> }}".
My test is just like a cartesian product of possibilities of open and close pairs/triples, I may should shorten it.
Comment 9 Dan Collins 2011-07-31 23:42:23 UTC
Created attachment 8859 [details]
Single unified patch against phase3 with code changes and (passing!) parser test

I just took the patch and the proposed test, fixed a few whitespace issues with the test, applied the patch, set up the test, and the test is passing. This patch incorporates the three initial attachments.
Comment 10 Sumana Harihareswara 2011-11-24 19:38:46 UTC
Dan, thank you for the patch and the parser test!  They are very much appreciated.  I'm notifying Gabriel Wicke, who is working on rewriting the parser.

In the few months since you made attachment 8859 [details], the trunk has changed a little; would you mind updating it to work against MediaWiki as it is in Subversion now?  We'd appreciate that.  Thank you.  I'm sorry for the delay and the inconvenience.
Comment 11 Sumana Harihareswara 2011-11-24 19:39:46 UTC
Comment on attachment 8859 [details]
Single unified patch against phase3 with code changes and (passing!) parser test

Per automated testing
http://lists.wikimedia.org/pipermail/wikitech-l/2011-November/056340.html patch
no longer applies to MediaWiki trunk in Subversion.  Requesting update.
Comment 12 Dan Collins 2011-11-24 20:55:04 UTC
Created attachment 9549 [details]
Updated patch against r104190

What's this, Sumana, you're working on thanksgiving?

Per manual testing, the only failing hunk from the original patch had the effect of removing a single line, which by the way was already commented out. Here is the updated patch.
Comment 13 Sumana Harihareswara 2011-11-25 19:20:39 UTC
Dan, I am basically taking the long weekend off, but I find that gardening Bugzilla is a little bit calming, like how some people pop the bubbles in bubble wrap.  :-)

Added the "patch" and "need-review" keywords to signal that there's a patch here that awaits review.  Please do feel free to add them the next time you attach a new patch that another developer should review.  Thanks for the update.
Comment 14 Dan Collins 2012-05-23 19:30:08 UTC
See Gerrit change #8511
Comment 15 Bartosz Dziewoński 2013-02-06 16:30:08 UTC
Merged -> marking as fixed.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links