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

Commit

Permalink
Add whitelist and blacklist for extensions to use and ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Mar 27, 2015
1 parent a005b8a commit 0819785
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/extensions/default/QuickView/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,20 @@ define(function (require, exports, module) {
var docPath = editor.document.file.fullPath;
var imgPath;

if (PathUtils.isAbsoluteUrl(tokenString)) {
// Lists of common extensions that we know will and won't produce useful img resources
var extWhitelist = ['.gif', '.png', '.jpg', '.jpeg', '.svg', '.bmp'];
var extBlacklist = ['.json', '.htm', '.html', '.css', '.less', '.js', '.md', '.xml'];

var parsed = PathUtils.parseUrl(tokenString);
var protocol = parsed.protocol;
var ext = parsed.filenameExtension;

// Use this URL if this is an absolute URL and doesn't point to a blacklisted extension
if (protocol !== "" && extBlacklist.indexOf(ext) === -1) {
imgPath = tokenString;
} else if (/(\.gif|\.png|\.jpg|\.jpeg|\.svg|\.bmp)$/i.test(tokenString)) {
}
// Use this filename if this is a path with a whitelisted extension
else if (protocol === "" && extWhitelist.indexOf(ext) > -1) {
imgPath = "file:///" + FileUtils.getDirectoryPath(docPath) + tokenString;
} else {
return null;
Expand Down

0 comments on commit 0819785

Please sign in to comment.