Skip to content

Commit

Permalink
Fix crash from tag name collision with Object properties in tag selector
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Jul 13, 2017
1 parent 4ffbf6f commit 1247896
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions chrome/content/zotero/bindings/tagselector.xml
Expand Up @@ -121,23 +121,25 @@

<field name="_hasScope">false</field>
<field name="_scope">null</field>
<property name="scope" onget="return this._scope">
<property name="scope">
<setter>
<![CDATA[
if (val.length) {
this._hasScope = true;
this._scope = {};
this._scope = new Map();
for (let i=0; i<val.length; i++) {
let tag = val[i];
if (!this._scope[tag.tag]) {
this._scope[tag.tag] = [];
let types = this._scope.get(tag.tag);
if (!types) {
types = []
}
this._scope[tag.tag].push(tag.type || 0);
types.push(tag.type || 0);
this._scope.set(tag.tag, types);
}
}
else {
this._hasScope = false;
this._scope = {};
this._scope = new Map();
}
this.refresh();
Expand Down Expand Up @@ -268,21 +270,21 @@
// Otherwise just update based on visibility
else {
// If only a few tags, regenerate buttons from scratch
if (this.filterToScope && Object.keys(this.scope).length <= 100) {
if (this.filterToScope && this._scope.size <= 100) {
// If full set is currently displayed, store it for later
if (!this._tagsDiv) {
this._tagsDiv = tagsBox.firstChild;
}
let tags = [];
for (let name in this.scope) {
tags.push(...this.scope[name].map(type => {
this._scope.forEach(function (types, name) {
tags.push(...types.map(type => {
return {
tag: name,
type: type
type
};
}));
}
});
let { div, emptyRegular } = this.createTagsList(tags);
tagsBox.replaceChild(div, tagsBox.firstChild);
this._emptyRegular = emptyRegular;
Expand Down Expand Up @@ -944,7 +946,7 @@
// Check tags against scope
if (this._hasScope) {
var inScope = !!this._scope[name];
var inScope = this._scope.has(name);
}
// If not in search, hide
Expand Down

0 comments on commit 1247896

Please sign in to comment.