Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 0819785

Browse files
committed
Add whitelist and blacklist for extensions to use and ignore
1 parent a005b8a commit 0819785

File tree

1 file changed

+13
-2
lines changed
  • src/extensions/default/QuickView

1 file changed

+13
-2
lines changed

src/extensions/default/QuickView/main.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,20 @@ define(function (require, exports, module) {
460460
var docPath = editor.document.file.fullPath;
461461
var imgPath;
462462

463-
if (PathUtils.isAbsoluteUrl(tokenString)) {
463+
// Lists of common extensions that we know will and won't produce useful img resources
464+
var extWhitelist = ['.gif', '.png', '.jpg', '.jpeg', '.svg', '.bmp'];
465+
var extBlacklist = ['.json', '.htm', '.html', '.css', '.less', '.js', '.md', '.xml'];
466+
467+
var parsed = PathUtils.parseUrl(tokenString);
468+
var protocol = parsed.protocol;
469+
var ext = parsed.filenameExtension;
470+
471+
// Use this URL if this is an absolute URL and doesn't point to a blacklisted extension
472+
if (protocol !== "" && extBlacklist.indexOf(ext) === -1) {
464473
imgPath = tokenString;
465-
} else if (/(\.gif|\.png|\.jpg|\.jpeg|\.svg|\.bmp)$/i.test(tokenString)) {
474+
}
475+
// Use this filename if this is a path with a whitelisted extension
476+
else if (protocol === "" && extWhitelist.indexOf(ext) > -1) {
466477
imgPath = "file:///" + FileUtils.getDirectoryPath(docPath) + tokenString;
467478
} else {
468479
return null;

0 commit comments

Comments
 (0)