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

"url", "src", and "href" parser rules allow values to begin with "//". #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/dom/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ wysihtml5.dom.parse = (function() {
// ------------ attribute checks ------------ \\
var attributeCheckMethods = {
url: (function() {
var REG_EXP = /^https?:\/\//i;
var REG_EXP = /^(https?:)?\/\//i;
return function(attributeValue) {
if (!attributeValue || !attributeValue.match(REG_EXP)) {
return null;
Expand All @@ -384,7 +384,7 @@ wysihtml5.dom.parse = (function() {
})(),

src: (function() {
var REG_EXP = /^(\/|https?:\/\/)/i;
var REG_EXP = /^(\/\/?|https?:\/\/)/i;
return function(attributeValue) {
if (!attributeValue || !attributeValue.match(REG_EXP)) {
return null;
Expand All @@ -396,7 +396,7 @@ wysihtml5.dom.parse = (function() {
})(),

href: (function() {
var REG_EXP = /^(\/|https?:\/\/|mailto:)/i;
var REG_EXP = /^(\/\/?|https?:\/\/|mailto:)/i;
return function(attributeValue) {
if (!attributeValue || !attributeValue.match(REG_EXP)) {
return null;
Expand Down
10 changes: 9 additions & 1 deletion test/dom/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ if (wysihtml5.browser.supported()) {
this.equal(
this.sanitize(
'<img src="http://url.gif">' +
'<img src="//same_protocol.gif">' +
'<img src="/path/to/absolute%20href.gif">' +
'<img src="mango time">',
rules
),
'<img src="http://url.gif"><img><img>'
'<img src="http://url.gif">' +
'<img src="//same_protocol.gif">' +
'<img>' +
'<img>'
);
});

Expand All @@ -142,12 +146,14 @@ if (wysihtml5.browser.supported()) {
this.sanitize(
'<img src="HTTP://url.gif">' +
'<img src="/path/to/absolute%20href.gif">' +
'<img src="//same_protocol.gif">' +
'<img src="mailto:[email protected]">' +
'<img src="mango time">',
rules
),
'<img src="http://url.gif">' +
'<img src="/path/to/absolute%20href.gif">' +
'<img src="//same_protocol.gif">' +
'<img>' +
'<img>'
);
Expand All @@ -167,6 +173,7 @@ if (wysihtml5.browser.supported()) {
'<a href="/foobar"></a>' +
'<a href="HTTPS://google.com"></a>' +
'<a href="http://google.com"></a>' +
'<a href="//google.com"></a>' +
'<a href="MAILTO:[email protected]"></a>' +
'<a href="mango time"></a>' +
'<a href="ftp://google.com"></a>',
Expand All @@ -175,6 +182,7 @@ if (wysihtml5.browser.supported()) {
'<a href="/foobar"></a>' +
'<a href="https://google.com"></a>' +
'<a href="http://google.com"></a>' +
'<a href="//google.com"></a>' +
'<a href="mailto:[email protected]"></a>' +
'<a></a>' +
'<a></a>'
Expand Down