Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #273 from tildeio/protocol-for-url
Browse files Browse the repository at this point in the history
Add hook for extracting protocol from URLs
  • Loading branch information
tomdale committed Jan 31, 2015
2 parents 513c917 + acb274d commit db589d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/morph/lib/dom-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,16 @@ prototype.parseHTML = function(html, contextualElement) {
}
};

var parsingNode;

// Used to determine whether a URL needs to be sanitized.
prototype.protocolForURL = function(url) {
if (!parsingNode) {
parsingNode = this.document.createElement('a');
}

parsingNode.href = url;
return parsingNode.protocol;
};

export default DOMHelper;
10 changes: 10 additions & 0 deletions packages/morph/tests/dom-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ test('#parseHTML of number', function(){
equalHTML(nodes, '5');
});

test('#protocolForURL', function() {
var protocol = dom.protocolForURL("http://www.emberjs.com");
equal(protocol, "http:");

// Inherit protocol from document if unparseable
protocol = dom.protocolForURL(" javascript:lulzhacked()");
/*jshint scripturl:true*/
equal(protocol, "javascript:");
});

test('#cloneNode shallow', function(){
var divElement = document.createElement('div');

Expand Down

0 comments on commit db589d9

Please sign in to comment.