From 07d1cb89067e8e64cfb46be05636d0f3d2dfdd10 Mon Sep 17 00:00:00 2001 From: Nick Hoffman Date: Tue, 10 Sep 2013 20:53:12 -0400 Subject: [PATCH] "url", "src", and "href" parser rules allow values to begin with "//". This is necessary because many URLs omit the protocol. E.g. --- src/dom/parse.js | 6 +++--- test/dom/parse_test.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/dom/parse.js b/src/dom/parse.js index f7868f94..b2f28c86 100644 --- a/src/dom/parse.js +++ b/src/dom/parse.js @@ -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; @@ -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; @@ -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; diff --git a/test/dom/parse_test.js b/test/dom/parse_test.js index fbce57e7..03059ac3 100644 --- a/test/dom/parse_test.js +++ b/test/dom/parse_test.js @@ -121,11 +121,15 @@ if (wysihtml5.browser.supported()) { this.equal( this.sanitize( '' + + '' + '' + '', rules ), - '' + '' + + '' + + '' + + '' ); }); @@ -142,12 +146,14 @@ if (wysihtml5.browser.supported()) { this.sanitize( '' + '' + + '' + '' + '', rules ), '' + '' + + '' + '' + '' ); @@ -167,6 +173,7 @@ if (wysihtml5.browser.supported()) { '' + '' + '' + + '' + '' + '' + '', @@ -175,6 +182,7 @@ if (wysihtml5.browser.supported()) { '' + '' + '' + + '' + '' + '' + ''