From bcd5572be26a5da7a5c01a585c07cde91af0d4f8 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Thu, 14 Sep 2017 10:44:42 -0400 Subject: [PATCH] Fix further crashes from non-string template targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Follow up to 5608e83f, where the possiblity of a non-string first token was anticipated. * Renders /am.wikipedia.org/v3/page/html/መለጠፊያ%3AIf/89130 Change-Id: I119953e4e2541be99e987a4126c9c0f1c1204359 --- lib/wt2html/tt/TemplateHandler.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/wt2html/tt/TemplateHandler.js b/lib/wt2html/tt/TemplateHandler.js index 2ba19899d..ed0794344 100644 --- a/lib/wt2html/tt/TemplateHandler.js +++ b/lib/wt2html/tt/TemplateHandler.js @@ -481,13 +481,19 @@ TemplateHandler.prototype.resolveTemplateTarget = function(state, targetToks) { // Strip ":" after skipping empty tokens, if any if (isPF) { while (firstTok === '') { - firstTok = targetToks[0]; // FIXME: Isn't guaranteed to be a string + firstTok = targetToks[0]; targetToks = targetToks.slice(1); } - console.assert(firstTok[0] === ':', 'Expecting : in parser function definiton'); - firstTok = firstTok.slice(1); + if (typeof firstTok === 'string') { + console.assert(firstTok[0] === ':', 'Expecting : in parser function definiton'); + pfArgToks = [firstTok.slice(1)].concat(targetToks); + } else { + // FIXME: Again, protect from crashers. See below. + pfArgToks = targetToks; + } + } else { + pfArgToks = [firstTok].concat(targetToks); } - pfArgToks = [firstTok].concat(targetToks); } else { // FIXME: In the scenario where the target itself is not a string, // protect from crashers by using the full token -- this is still