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

Homepage url validation for extension listing #12389

Merged
merged 6 commits into from
May 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/extensibility/ExtensionManagerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
/*global define, $, brackets */
/*global define, $, brackets, Mustache, PathUtils */
/*unittests: ExtensionManager*/

define(function (require, exports, module) {
Expand All @@ -35,9 +35,15 @@ define(function (require, exports, module) {
registry_utils = require("extensibility/registry_utils"),
InstallExtensionDialog = require("extensibility/InstallExtensionDialog"),
LocalizationUtils = require("utils/LocalizationUtils"),
LanguageManager = require("language/LanguageManager"),
itemTemplate = require("text!htmlContent/extension-manager-view-item.html"),
Mustache = require("thirdparty/mustache/mustache");

/**
* Create a detached link element, so that we can use it later to extract url details like 'protocol'
*/
var _tmpLink = document.createElement('a');

/**
* Creates a view enabling the user to install and manage extensions. Must be initialized
* with initialize(). When the view is closed, dispose() must be called.
Expand Down Expand Up @@ -337,6 +343,24 @@ define(function (require, exports, module) {
context[helper] = registry_utils[helper];
});

// Do some extra validation on homepage url to make sure we don't end up executing local binary
if (context.metadata.homepage) {
var parsed = PathUtils.parseUrl(context.metadata.homepage);

// We can't rely on path-utils because of known problems with protocol identification
// Falling back to Browsers protocol identification mechanism
_tmpLink.href = context.metadata.homepage;

// Check if the homepage refers to a local resource
if (_tmpLink.protocol === "file:") {
var language = LanguageManager.getLanguageForExtension(parsed.filenameExtension.replace(/^\./, ''));
// If identified language for the local resource is binary, don't list it
if (language && language.isBinary()) {
delete context.metadata.homepage;
}
}
}

return $(this._itemTemplate(context));
};

Expand Down