From 6d0eb7178ddaa16355349b8da98e8ea916b257bb Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 17 Aug 2020 17:40:34 +0200 Subject: [PATCH] FIX: prevents errors on /tags when a tag `constructor` exists (#10449) This is due to js objects having a constructor property: ``` const obj = {}; obj['constructor'] // return [native code] and not undefined ``` --- app/assets/javascripts/discourse/app/models/store.js | 6 +++--- app/models/tag.rb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/store.js b/app/assets/javascripts/discourse/app/models/store.js index 4cf09944bc0..2070af746a2 100644 --- a/app/assets/javascripts/discourse/app/models/store.js +++ b/app/assets/javascripts/discourse/app/models/store.js @@ -25,21 +25,21 @@ function storeMap(type, id, obj) { function fromMap(type, id) { const byType = _identityMap[type]; - if (byType) { + if (byType && byType.hasOwnProperty(id)) { return byType[id]; } } function removeMap(type, id) { const byType = _identityMap[type]; - if (byType) { + if (byType && byType.hasOwnProperty(id)) { delete byType[id]; } } function findAndRemoveMap(type, id) { const byType = _identityMap[type]; - if (byType) { + if (byType && byType.hasOwnProperty(id)) { const result = byType[id]; delete byType[id]; return result; diff --git a/app/models/tag.rb b/app/models/tag.rb index 3a005e77e42..9f6ade238e0 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -5,7 +5,8 @@ class Tag < ActiveRecord::Base include HasDestroyedWebHook RESERVED_TAGS = [ - 'none' + 'none', + 'constructor' # prevents issues with javascript's constructor of objects ] validates :name,