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

Add hook for extracting protocol from URLs #273

Merged
merged 2 commits into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
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
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