(Bug 49490) Prefix ref name/group before using as property key

* The page in question "es:Estadio_Deportivo_Cali" had a ref
  with name "constructor", and this name was used as an object
  property key and this clashed with the predefined property
  constructor.

* The reliable solution here is to prefix ref-name and ref-group
  with a string and use it to prevent clashes.

Change-Id: Ib5cf7cce6fa4acd88e3d49ca9d4390a61bfddd7e
This commit is contained in:
Subramanya Sastry 2013-06-12 14:26:36 -05:00
parent d6a53a5874
commit fdf5fa4bd0

View file

@ -139,9 +139,12 @@ function RefGroup(group) {
} }
RefGroup.prototype.add = function(refName, about, skipLinkback) { RefGroup.prototype.add = function(refName, about, skipLinkback) {
// NOTE: prefix name with "ref:" before using it as a property key
// This is to avoid overwriting predefined keys like 'constructor'
var ref; var ref;
if (refName && this.indexByName[refName]) { if (refName && this.indexByName["ref:" + refName]) {
ref = this.indexByName[refName]; ref = this.indexByName["ref:" + refName];
} else { } else {
var n = this.refs.length, var n = this.refs.length,
refKey = (1+n) + ''; refKey = (1+n) + '';
@ -163,7 +166,7 @@ RefGroup.prototype.add = function(refName, about, skipLinkback) {
}; };
this.refs[n] = ref; this.refs[n] = ref;
if (refName) { if (refName) {
this.indexByName[refName] = ref; this.indexByName["ref:" + refName] = ref;
} }
} }
@ -235,8 +238,11 @@ function References(cite) {
} }
References.prototype.reset = function(group) { References.prototype.reset = function(group) {
// NOTE: prefix name with "refgroup:" before using it as a property key
// This is to avoid overwriting predefined keys like 'constructor'
if (group) { if (group) {
this.refGroups[group] = undefined; this.refGroups["refgroup:" + group] = undefined;
} else { } else {
this.refGroups = {}; this.refGroups = {};
} }
@ -310,19 +316,22 @@ References.prototype.handleReferences = function ( manager, pipelineOpts, refsTo
}; };
References.prototype.extractRefFromNode = function(node) { References.prototype.extractRefFromNode = function(node) {
function newRefGroup(refGroups, group) { // NOTE: prefix name with "refgroup:" before using it as a property key
// This is to avoid overwriting predefined keys like 'constructor'
function getRefGroup(refGroups, group) {
group = group || ''; group = group || '';
if (!refGroups[group]) { var key = "refgroup:" + group;
refGroups[group] = new RefGroup(group); if (!refGroups[key]) {
refGroups[key] = new RefGroup(group);
} }
return refGroups[group]; return refGroups[key];
} }
var group = node.getAttribute("group"), var group = node.getAttribute("group"),
refName = node.getAttribute("name"), refName = node.getAttribute("name"),
about = node.getAttribute("about"), about = node.getAttribute("about"),
skipLinkback = node.getAttribute("skiplinkback") === "1", skipLinkback = node.getAttribute("skiplinkback") === "1",
refGroup = this.refGroups[group] || newRefGroup(this.refGroups, group), refGroup = getRefGroup(this.refGroups, group),
ref = refGroup.add(refName, about, skipLinkback); ref = refGroup.add(refName, about, skipLinkback);
// Add ref-index linkback // Add ref-index linkback