Skip to content

Commit

Permalink
Give each link in HTML message a new target window
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 8, 2014
1 parent a891954 commit e35ca26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 4 additions & 8 deletions imp/lib/Mime/Viewer/Html.php
Expand Up @@ -148,9 +148,7 @@ protected function _IMPrender($inline)

/* Don't do IMP DOM processing if in mimp mode or converting to
* text. */
$this->_imptmp = array(
'target' => strval(new Horde_Support_Randomid())
);
$this->_imptmp = array();
if ($inline && !$convert_text) {
$this->_imptmp += array(
'blockimg' => null,
Expand All @@ -161,8 +159,7 @@ protected function _IMPrender($inline)
'img' => false,
'imgblock' => false,
'inline' => $inline,
'style' => array(),
'target' => strval(new Horde_Support_Randomid())
'style' => array()
);

if ($inline) {
Expand Down Expand Up @@ -334,9 +331,8 @@ protected function _node($doc, $node)
/* See Bug #8695: internal anchors are broken in
* Mozilla. */
$node->removeAttribute('href');
} elseif (!$node->hasAttribute('target') ||
Horde_String::lower($node->getAttribute('target')) == '_self') {
$node->setAttribute('target', $this->_imptmp['target']);
} else {
$node->setAttribute('target', strval(new Horde_Support_Randomid()));
}
}
break;
Expand Down
14 changes: 7 additions & 7 deletions imp/test/Imp/Unit/Mime/Viewer/HtmlTest.php
Expand Up @@ -42,13 +42,13 @@ public function testOpenLinksInNewWindow()
$links = array(
'foo' => '<p>foo</p>',
'example@example.com' => '<p>example@example.com</p>',
'foo <a href="#bar">Anchor</a>' => '<p>foo <a href="#bar" target="_blank">Anchor</a></p>',
'foo <a href="http://www.example.com/">example</a>' => '<p>foo <a href="http://www.example.com/" target="_blank">example</a></p>',
'foo <a target="foo" href="http://www.example.com/">example</a>' => '<p>foo <a target="foo" href="http://www.example.com/">example</a></p>',
'foo <a href="http://www.example.com/" target="foo">example</a>' => '<p>foo <a href="http://www.example.com/" target="foo">example</a></p>',
'foo <a href="#bar">Anchor</a>' => '<p>foo <a href="#bar" target="%s">Anchor</a></p>',
'foo <a href="http://www.example.com/">example</a>' => '<p>foo <a href="http://www.example.com/" target="%s">example</a></p>',
'foo <a target="foo" href="http://www.example.com/">example</a>' => '<p>foo <a target="%s" href="http://www.example.com/">example</a></p>',
'foo <a href="http://www.example.com/" target="foo">example</a>' => '<p>foo <a href="http://www.example.com/" target="%s">example</a></p>',
'foo <a mailto="example@example.com">Example Email</a>' => '<p>foo <a mailto="example@example.com">Example Email</a></p>',
'<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/"></map>' => '<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="_blank"/></map>',
'<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="foo"></map>' => '<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="foo"/></map>'
'<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/"></map>' => '<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="%s"/></map>',
'<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="foo"></map>' => '<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="%s"/></map>'
);

$v = new IMP_Stub_Mime_Viewer_Html(new Horde_Mime_Part(), array(
Expand All @@ -57,7 +57,7 @@ public function testOpenLinksInNewWindow()
));

foreach ($links as $key => $val) {
$this->assertEquals(
$this->assertStringMatchesFormat(
$val,
$v->runTest($key)
);
Expand Down

0 comments on commit e35ca26

Please sign in to comment.