From 47f9106c42c0759e931e50acda11c6d4b5ebea48 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 19 Nov 2021 08:21:42 +0000 Subject: [PATCH] MDL-73121 atto_managefiles: match used files enclosed by quotes. --- .../moodle-atto_managefiles-usedfiles-debug.js | 3 ++- .../moodle-atto_managefiles-usedfiles-min.js | 2 +- .../moodle-atto_managefiles-usedfiles.js | 3 ++- .../atto/plugins/managefiles/yui/src/usedfiles/js/usedfiles.js | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-debug.js b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-debug.js index eef8a6480a617..1b36bece62b94 100644 --- a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-debug.js +++ b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-debug.js @@ -151,11 +151,12 @@ M.atto_managefiles.usedfiles = M.atto_managefiles.usedfiles || { _getUsedFiles: function() { var content = Y.one(window.parent.document.getElementById(this._elementid + 'editable')), baseUrl = M.cfg.wwwroot + '/draftfile.php/' + this._usercontext + '/user/draft/' + this._itemid + '/', - pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), + pattern = new RegExp("[\"']" + baseUrl.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), filename = '', match = '', usedFiles = {}; + // The pattern matches any draftfile URL contained within quotes, e.g. 'src=""' or 'href=""'. while ((match = pattern.exec(content.get('innerHTML'))) !== null) { filename = decodeURIComponent(match[1]); usedFiles[filename] = true; diff --git a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-min.js b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-min.js index 90153d95dbf38..c829ff39f089c 100644 --- a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-min.js +++ b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_managefiles-usedfiles",function(d,e){var o="has-missing-files",f="has-unused-files",r=".fitem",u="#atto_managefiles_manageform",m=".missing-files";M.atto_managefiles=M.atto_managefiles||{},M.atto_managefiles.usedfiles=M.atto_managefiles.usedfiles||{_usercontext:null,_itemid:null,_elementid:null,init:function(e){var i,n,t,s,l,a;if(this._usercontext=e.usercontext,this._itemid=e.itemid,this._elementid=e.elementid,e=e.files,(i=d.one(u))&&window.parent)if(n=this._getUsedFiles(),t=this.findUnusedFiles(e,n),s=this.findMissingFiles(e,n),0",a=0;a"+d.Escape.html(s[a])+"";l+="",i.one(m).setHTML("").append(l),i.addClass(o)}else i.removeClass(o)},_getUsedFiles:function(){for(var e,i=d.one(window.parent.document.getElementById(this._elementid+"editable")),n=M.cfg.wwwroot+"/draftfile.php/"+this._usercontext+"/user/draft/"+this._itemid+"/",t=new RegExp(n.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g,"\\$&")+"(.+?)[\\?\"']","gm"),s={};null!==(e=t.exec(i.get("innerHTML")));)s[decodeURIComponent(e[1])]=!0;return s},findUnusedFiles:function(e,i){var n,t=[];for(n in e)i[n]||t.push(n);return t},findMissingFiles:function(e,i){var n,t=[];for(n in i)e[n]||t.push(n);return t}}},"@VERSION@",{requires:["node","escape"]}); \ No newline at end of file +YUI.add("moodle-atto_managefiles-usedfiles",function(d,e){var o="has-missing-files",f="has-unused-files",r=".fitem",u="#atto_managefiles_manageform",m=".missing-files";M.atto_managefiles=M.atto_managefiles||{},M.atto_managefiles.usedfiles=M.atto_managefiles.usedfiles||{_usercontext:null,_itemid:null,_elementid:null,init:function(e){var i,n,t,s,l,a;if(this._usercontext=e.usercontext,this._itemid=e.itemid,this._elementid=e.elementid,e=e.files,(i=d.one(u))&&window.parent)if(n=this._getUsedFiles(),t=this.findUnusedFiles(e,n),s=this.findMissingFiles(e,n),0",a=0;a"+d.Escape.html(s[a])+"";l+="",i.one(m).setHTML("").append(l),i.addClass(o)}else i.removeClass(o)},_getUsedFiles:function(){for(var e,i=d.one(window.parent.document.getElementById(this._elementid+"editable")),n=M.cfg.wwwroot+"/draftfile.php/"+this._usercontext+"/user/draft/"+this._itemid+"/",t=new RegExp("[\"']"+n.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")+"(.+?)[\\?\"']","gm"),s={};null!==(e=t.exec(i.get("innerHTML")));)s[decodeURIComponent(e[1])]=!0;return s},findUnusedFiles:function(e,i){var n,t=[];for(n in e)i[n]||t.push(n);return t},findMissingFiles:function(e,i){var n,t=[];for(n in i)e[n]||t.push(n);return t}}},"@VERSION@",{requires:["node","escape"]}); \ No newline at end of file diff --git a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles.js b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles.js index ae2668e7dc1e4..d15f24e5a403c 100644 --- a/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles.js +++ b/lib/editor/atto/plugins/managefiles/yui/build/moodle-atto_managefiles-usedfiles/moodle-atto_managefiles-usedfiles.js @@ -150,11 +150,12 @@ M.atto_managefiles.usedfiles = M.atto_managefiles.usedfiles || { _getUsedFiles: function() { var content = Y.one(window.parent.document.getElementById(this._elementid + 'editable')), baseUrl = M.cfg.wwwroot + '/draftfile.php/' + this._usercontext + '/user/draft/' + this._itemid + '/', - pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), + pattern = new RegExp("[\"']" + baseUrl.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), filename = '', match = '', usedFiles = {}; + // The pattern matches any draftfile URL contained within quotes, e.g. 'src=""' or 'href=""'. while ((match = pattern.exec(content.get('innerHTML'))) !== null) { filename = decodeURIComponent(match[1]); usedFiles[filename] = true; diff --git a/lib/editor/atto/plugins/managefiles/yui/src/usedfiles/js/usedfiles.js b/lib/editor/atto/plugins/managefiles/yui/src/usedfiles/js/usedfiles.js index 534a2b79b69b7..863ddfef6d77a 100644 --- a/lib/editor/atto/plugins/managefiles/yui/src/usedfiles/js/usedfiles.js +++ b/lib/editor/atto/plugins/managefiles/yui/src/usedfiles/js/usedfiles.js @@ -149,11 +149,12 @@ M.atto_managefiles.usedfiles = M.atto_managefiles.usedfiles || { _getUsedFiles: function() { var content = Y.one(window.parent.document.getElementById(this._elementid + 'editable')), baseUrl = M.cfg.wwwroot + '/draftfile.php/' + this._usercontext + '/user/draft/' + this._itemid + '/', - pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), + pattern = new RegExp("[\"']" + baseUrl.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'), filename = '', match = '', usedFiles = {}; + // The pattern matches any draftfile URL contained within quotes, e.g. 'src=""' or 'href=""'. while ((match = pattern.exec(content.get('innerHTML'))) !== null) { filename = decodeURIComponent(match[1]); usedFiles[filename] = true;