Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234460
Change subject: Be careful about using tsr in tokens/x-mediawiki phase
......................................................................
Be careful about using tsr in tokens/x-mediawiki phase
* The tsr info is only stripped from tokens once emitted from the
pipeline. Make explicit checks that we aren't inTemplate.
* This problem can be seen in the origTxt of the link in the test
called "Parsoid: pipe in transclusion parameter".
Change-Id: I0bf5c259c926bbb60ac2524d510f086a92ce7311
---
M lib/dom.t.TableFixups.js
M lib/ext.core.LinkHandler.js
M lib/ext.core.NoIncludeOnly.js
M lib/ext.core.Sanitizer.js
4 files changed, 13 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/60/234460/1
diff --git a/lib/dom.t.TableFixups.js b/lib/dom.t.TableFixups.js
index 55dc996..e83769a 100644
--- a/lib/dom.t.TableFixups.js
+++ b/lib/dom.t.TableFixups.js
@@ -33,7 +33,7 @@
env: env,
addTransform: function() {},
};
- this.sanitizer = new Sanitizer(fakeManager);
+ this.sanitizer = new Sanitizer(fakeManager, {});
}
/**
diff --git a/lib/ext.core.LinkHandler.js b/lib/ext.core.LinkHandler.js
index deadadd..73b6395 100644
--- a/lib/ext.core.LinkHandler.js
+++ b/lib/ext.core.LinkHandler.js
@@ -1445,6 +1445,7 @@
};
function ExternalLinkHandler(manager, options) {
+ this.options = options;
this.manager = manager;
this.manager.addTransform(this.onUrlLink.bind(this),
"ExternalLinkHandler:onUrlLink", this.rank, 'tag', 'urllink');
this.manager.addTransform(this.onExtLink.bind(this),
"ExternalLinkHandler:onExtLink",
@@ -1498,7 +1499,6 @@
var tagAttrs, builtTag;
var env = this.manager.env;
var href = Util.tokensToString(Util.lookup(token.attribs, 'href'));
- var origTxt = token.getWTSource(env);
var txt = href;
if (SanitizerConstants.IDN_RE.test(txt)) {
@@ -1529,14 +1529,12 @@
builtTag = new TagTk('a', tagAttrs, dataAttribs);
dataAttribs.stx = 'url';
- if (origTxt) {
- // origTxt will be null for content from templates
- //
+ if (!this.options.inTemplate) {
// Since we messed with the text of the link, we need
// to preserve the original in the RT data. Or else.
- builtTag.addNormalizedAttribute('href', txt, origTxt);
+ builtTag.addNormalizedAttribute('href', txt,
token.getWTSource(env));
} else {
- builtTag.addAttribute('href',
token.getAttribute('href'));
+ builtTag.addAttribute('href', txt);
}
cb({
diff --git a/lib/ext.core.NoIncludeOnly.js b/lib/ext.core.NoIncludeOnly.js
index 2afe089..b323e6c 100644
--- a/lib/ext.core.NoIncludeOnly.js
+++ b/lib/ext.core.NoIncludeOnly.js
@@ -54,6 +54,7 @@
* onlyinclude processing (which is a good idea anyway).
*/
function OnlyInclude(manager, options) {
+ this.options = options;
this.manager = manager;
if (options.isInclude) {
this.accum = [];
@@ -72,7 +73,8 @@
OnlyInclude.prototype.onOnlyInclude = function(token, manager) {
var tsr = (token.dataAttribs || {}).tsr;
- var src = tsr[1] ? token.getWTSource(manager.env) : undefined;
+ var src = !this.options.inTemplate && Array.isArray(tsr) && tsr[1] ?
+ token.getWTSource(manager.env) : undefined;
var attribs = [
new KV('typeof', 'mw:Includes/OnlyInclude' + (token instanceof
EndTagTk ? '/End' : '')),
];
diff --git a/lib/ext.core.Sanitizer.js b/lib/ext.core.Sanitizer.js
index 82ed097..f30c1eb 100644
--- a/lib/ext.core.Sanitizer.js
+++ b/lib/ext.core.Sanitizer.js
@@ -588,7 +588,8 @@
* @constructor
* @param {TokenTransformManager} manager The manager for this part of the
pipeline.
*/
-function Sanitizer(manager) {
+function Sanitizer(manager, options) {
+ this.options = options;
// FIXME: would be good to make the sanitizer independent of the manager
// so that it can be used separately. See
// https://phabricator.wikimedia.org/T54941
@@ -710,10 +711,9 @@
) { // unknown tag -- convert to plain text
var origToken = token;
- if (token.dataAttribs.tsr) {
- // TSR is only set on top-level content tokens, for
which the page
- // source is available in the environment. Just get the
original
- // token source, so that we can avoid whitespace
differences.
+ if (!this.options.inTemplate && token.dataAttribs.tsr) {
+ // Just get the original token source, so that we can
avoid
+ // whitespace differences.
token = token.getWTSource(this.manager.env);
} else if (token.constructor !== EndTagTk) {
// Handle things without a TSR: For example template or
extension
--
To view, visit https://gerrit.wikimedia.org/r/234460
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bf5c259c926bbb60ac2524d510f086a92ce7311
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits