GWicke has submitted this change and it was merged.
Change subject: Fix buggy token passing in parserFunctions expandKV and
rejoinKV.
......................................................................
Fix buggy token passing in parserFunctions expandKV and rejoinKV.
* expandKV and rejoinKV were not always passing tokens back in
{ tokens: token-array } form to the callbacks. This was caught
by verifyTokensIntegrity check in Async TTM on the following
wikitext snippet from en:England_national_football_team
{{Football kit |
| pattern_la= |pattern_b= |pattern_ra= |pattern_sh= |pattern_so=
| leftarm=fff|body=fff|rightarm=fff|shorts=fff|socks=000000|title= Home
}}
* Surprisingly parsing the page via localhost:8000/en/... didn't
report the error to the console. Neither did a rt-run through
roundtrip-test.js. Need to check where the error went in case
the error message got lost rather than a different code path
getting exercised because of async. related reasons.
* Unrelated:
- s.res.tokens.rank wasn't being updated in maybeAsyncReturn.
- It appears some cb's in parserFunctions return {}.
Tweaked verifyToksIntegrity to accept {} and return
{ tokens:[] } instead.
- verifyToksIntegrity result wasn't being used in certain cases.
* No change in parser test results.
Change-Id: I15e4f922f259382e3241b2da7a8a22ec9b498841
---
M js/lib/ext.core.ParserFunctions.js
M js/lib/mediawiki.TokenTransformManager.js
2 files changed, 15 insertions(+), 10 deletions(-)
Approvals:
GWicke: Verified; Looks good to me, approved
diff --git a/js/lib/ext.core.ParserFunctions.js
b/js/lib/ext.core.ParserFunctions.js
index ef3ce69..0c27de4 100644
--- a/js/lib/ext.core.ParserFunctions.js
+++ b/js/lib/ext.core.ParserFunctions.js
@@ -28,7 +28,9 @@
// Temporary helper.
ParserFunctions.prototype._rejoinKV = function ( trim, k, v ) {
- if ( k.length ) {
+ if ( k.constructor === String && k.length > 0 ) {
+ return [k].concat( ['='], v );
+ } else if (k.constructor === Array && k.length > 0) {
return k.concat( ['='], v );
} else {
return trim ? Util.tokenTrim(v) : v;
@@ -47,7 +49,7 @@
if ( kv === undefined ) {
cb( { tokens: [ defaultValue || '' ] } );
} else if ( kv.constructor === String ) {
- return cb( kv );
+ return cb( { tokens: [kv] } );
} else if ( kv.k.constructor === String && kv.v.constructor === String
) {
if ( kv.k ) {
cb( { tokens: [kv.k + '=' + kv.v] } );
diff --git a/js/lib/mediawiki.TokenTransformManager.js
b/js/lib/mediawiki.TokenTransformManager.js
index 82e4e87..410efd4 100644
--- a/js/lib/mediawiki.TokenTransformManager.js
+++ b/js/lib/mediawiki.TokenTransformManager.js
@@ -27,14 +27,17 @@
console.warn(' ret is not an object: ' + JSON.stringify( ret )
);
console.trace();
ret = { tokens: ret };
- } else if (!nullOkay && ret.tokens === undefined) {
- console.warn( 'ret.tokens undefined: ' + JSON.stringify( ret )
);
- console.trace();
+ } else if (ret.tokens === undefined) {
+ if (!nullOkay) {
+ console.warn( 'ret.tokens undefined: ' +
JSON.stringify( ret ) );
+ console.trace();
+ }
ret.tokens = ( ret.token === undefined ) ? [] : [ret.token];
}
if (ret.tokens && ret.tokens.constructor !== Array) {
- console.warn( 'ret.tokens not an array: ' + JSON.stringify( ret
) );
+ console.warn( 'ret.tokens not an array: ' +
ret.tokens.constructor.name);
+ console.warn( 'ret.tokens: ' + JSON.stringify( ret ) );
console.trace();
ret.tokens = [ ret.tokens ];
}
@@ -694,7 +697,7 @@
// transformTokens is still ongoing, handle as sync return by
// collecting the results in s.res
this.env.dp( 'maybeSyncReturn transforming', s.c, ret );
- if ( ret.tokens ) {
+ if ( ret.tokens && ret.tokens.length > 0) {
if ( s.res.tokens ) {
var oldRank = s.res.tokens.rank;
s.res.tokens = s.res.tokens.concat( ret.tokens
);
@@ -702,7 +705,7 @@
// Conservatively set the overall rank
to the minimum.
// This assumes that multi-pass
expansion for some tokens
// is safe. We might want to revisit
that later.
- Math.min( oldRank, ret.tokens.rank );
+ s.res.tokens.rank = Math.min( oldRank,
ret.tokens.rank );
}
} else {
s.res = ret;
@@ -1134,7 +1137,7 @@
* @returns {Mixed}: new parent callback for caller or falsy value
*/
TokenAccumulator.prototype.receiveToksFromChild = function ( ret ) {
- verifyTokensIntegrity(ret, false);
+ ret = verifyTokensIntegrity(ret, false);
if ( !ret.async ) {
// Child is all done => can pass along sibling toks as well
// since any tokens we receive now will already be in order
@@ -1162,7 +1165,7 @@
* @returns {Mixed}: new parent callback for caller or falsy value
*/
TokenAccumulator.prototype.receiveToksFromSibling = function ( ret ) {
- verifyTokensIntegrity(ret, false);
+ ret = verifyTokensIntegrity(ret, false);
if (!ret.async) {
this.waitForSibling = false;
--
To view, visit https://gerrit.wikimedia.org/r/50380
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I15e4f922f259382e3241b2da7a8a22ec9b498841
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits