summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-02-01 20:04:00 +0100
committerAleksander Machniak <alec@alec.pl>2013-02-01 20:08:16 +0100
commit43aeb195c159cac8352f1eeb5148c060ff0b81b6 (patch)
treeae2709ea7289a77a34fe744da258f4c70434547b
parent85c972a4f79c7e9548a6cd7f9d9336c5f2886a4a (diff)
Fix handling link href attribute value with (valid) newline characters (#1488940)
-rw-r--r--program/lib/Roundcube/rcube_washtml.php3
-rw-r--r--tests/Framework/Washtml.php14
2 files changed, 16 insertions, 1 deletions
diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php
index 715c46047..2a261419f 100644
--- a/program/lib/Roundcube/rcube_washtml.php
+++ b/program/lib/Roundcube/rcube_washtml.php
@@ -240,7 +240,8 @@ class rcube_washtml
$value = $node->getAttribute($key);
if (isset($this->_html_attribs[$key]) ||
- ($key == 'href' && !preg_match('!^(javascript|vbscript|data:text)!i', $value)
+ ($key == 'href' && ($value = trim($value))
+ && !preg_match('!^(javascript|vbscript|data:text)!i', $value)
&& preg_match('!^([a-z][a-z0-9.+-]+:|//|#).+!i', $value))
) {
$t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php
index 088ac4a8c..6f4aa9783 100644
--- a/tests/Framework/Washtml.php
+++ b/tests/Framework/Washtml.php
@@ -25,4 +25,18 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
$this->assertNotRegExp('/vbscript:/', $washed, "Remove vbscript: links");
}
+ /**
+ * Test fixing of invalid href (#1488940)
+ */
+ function test_href()
+ {
+ $html = "<p><a href=\"\nhttp://test.com\n\">Firefox</a>";
+
+ $washer = new rcube_washtml;
+
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|href="http://test.com">|', $washed, "Link href with newlines (#1488940)");
+ }
+
}