[TASK] Store only valid icon markup into local storage 46/57146/2
authorFrank Naegler <frank.naegler@typo3.org>
Fri, 8 Jun 2018 08:02:18 +0000 (10:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 9 Jun 2018 15:22:57 +0000 (17:22 +0200)
This patch prevent putting invalid data into localStorage in the rare
case that the AJAX call does not provide icon markup.

Resolves: #85184
Releases: master
Change-Id: Icddd88232bf9ac5f77e08ed7fbac475af8b469eb
Reviewed-on: https://review.typo3.org/57146
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Resources/Private/TypeScript/Icons.ts
typo3/sysext/backend/Resources/Public/JavaScript/Icons.js

index 8568963..7e13e75 100644 (file)
@@ -122,7 +122,9 @@ class Icons {
           icon: JSON.stringify(icon)
         },
         success: (markup: string) => {
-          ClientStorage.set('icon_' + cacheIdentifier, markup);
+          if (markup.indexOf('t3js-icon') !== -1 && markup.indexOf('<span class="icon-markup">') !== -1) {
+            ClientStorage.set('icon_' + cacheIdentifier, markup);
+          }
           return markup;
         }
       }));
index b162f2a..9c5a722 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","./Storage/Client"],function(e,t,i,r){"use strict";var n,o,s,c,a,u;(o=n||(n={})).small="small",o.default="default",o.large="large",o.overlay="overlay",(c=s||(s={})).default="default",c.disabled="disabled",(u=a||(a={})).default="default",u.inline="inline";var h,f=function(){function e(){this.sizes=n,this.states=s,this.markupIdentifiers=a,this.promiseCache={}}return e.prototype.getIcon=function(e,t,o,c,u){var h=this,f=[e,t=t||n.default,o,c=c||s.default,u=u||a.default],l=f.join("_");return i.when(this.getIconRegistryCache()).pipe(function(e){return r.isset("icon_registry_cache_identifier")&&r.get("icon_registry_cache_identifier")===e||(r.unsetByPrefix("icon_"),r.set("icon_registry_cache_identifier",e)),h.fetchFromLocal(l).then(null,function(){return h.fetchFromRemote(f,l)})})},e.prototype.getIconRegistryCache=function(){var e="icon_registry_cache_identifier";return this.isPromiseCached(e)||this.putInPromiseCache(e,i.ajax({url:TYPO3.settings.ajaxUrls.icons_cache,success:function(e){return e}})),this.getFromPromiseCache(e)},e.prototype.fetchFromRemote=function(e,t){return this.isPromiseCached(t)||this.putInPromiseCache(t,i.ajax({url:TYPO3.settings.ajaxUrls.icons,dataType:"html",data:{icon:JSON.stringify(e)},success:function(e){return r.set("icon_"+t,e),e}})),this.getFromPromiseCache(t)},e.prototype.fetchFromLocal=function(e){var t=i.Deferred();return r.isset("icon_"+e)?t.resolve(r.get("icon_"+e)):t.reject(),t.promise()},e.prototype.isPromiseCached=function(e){return void 0!==this.promiseCache[e]},e.prototype.getFromPromiseCache=function(e){return this.promiseCache[e]},e.prototype.putInPromiseCache=function(e,t){this.promiseCache[e]=t},e}();return h||(h=new f,TYPO3.Icons=h),h});
\ No newline at end of file
+define(["require","exports","jquery","./Storage/Client"],function(e,t,i,r){"use strict";var n,s,o,c,a,u;(s=n||(n={})).small="small",s.default="default",s.large="large",s.overlay="overlay",(c=o||(o={})).default="default",c.disabled="disabled",(u=a||(a={})).default="default",u.inline="inline";var h,f=function(){function e(){this.sizes=n,this.states=o,this.markupIdentifiers=a,this.promiseCache={}}return e.prototype.getIcon=function(e,t,s,c,u){var h=this,f=[e,t=t||n.default,s,c=c||o.default,u=u||a.default],l=f.join("_");return i.when(this.getIconRegistryCache()).pipe(function(e){return r.isset("icon_registry_cache_identifier")&&r.get("icon_registry_cache_identifier")===e||(r.unsetByPrefix("icon_"),r.set("icon_registry_cache_identifier",e)),h.fetchFromLocal(l).then(null,function(){return h.fetchFromRemote(f,l)})})},e.prototype.getIconRegistryCache=function(){var e="icon_registry_cache_identifier";return this.isPromiseCached(e)||this.putInPromiseCache(e,i.ajax({url:TYPO3.settings.ajaxUrls.icons_cache,success:function(e){return e}})),this.getFromPromiseCache(e)},e.prototype.fetchFromRemote=function(e,t){return this.isPromiseCached(t)||this.putInPromiseCache(t,i.ajax({url:TYPO3.settings.ajaxUrls.icons,dataType:"html",data:{icon:JSON.stringify(e)},success:function(e){return-1!==e.indexOf("t3js-icon")&&-1!==e.indexOf('<span class="icon-markup">')&&r.set("icon_"+t,e),e}})),this.getFromPromiseCache(t)},e.prototype.fetchFromLocal=function(e){var t=i.Deferred();return r.isset("icon_"+e)?t.resolve(r.get("icon_"+e)):t.reject(),t.promise()},e.prototype.isPromiseCached=function(e){return void 0!==this.promiseCache[e]},e.prototype.getFromPromiseCache=function(e){return this.promiseCache[e]},e.prototype.putInPromiseCache=function(e,t){this.promiseCache[e]=t},e}();return h||(h=new f,TYPO3.Icons=h),h});
\ No newline at end of file