diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-10-08 09:40:29 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-10-08 09:40:29 +0200 |
commit | 8c12804991c564aafbb2508e473d7a915947d982 (patch) | |
tree | 8f8c427ae2b82be945cbfcdedb74df188d7e07b5 | |
parent | 6afe8dca1f7bd2a9ca21fb2dca6fef12ded423e1 (diff) | |
download | rpg-8c12804991c564aafbb2508e473d7a915947d982.tar.gz rpg-8c12804991c564aafbb2508e473d7a915947d982.tar.bz2 |
fixed images in email links
darcs-hash:20061008074029-7ad00-8457873dd8ad2f5a36dc8f44eca42a4378e61e93.gz
-rw-r--r-- | _test/cases/inc/parser/parser_links.test.php | 109 | ||||
-rw-r--r-- | _test/cases/inc/parser/xhtml_links.test.php | 41 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 9 |
3 files changed, 114 insertions, 45 deletions
diff --git a/_test/cases/inc/parser/parser_links.test.php b/_test/cases/inc/parser/parser_links.test.php index b7dd567c4..c98296bfd 100644 --- a/_test/cases/inc/parser/parser_links.test.php +++ b/_test/cases/inc/parser/parser_links.test.php @@ -2,12 +2,12 @@ require_once 'parser.inc.php'; class TestOfDoku_Parser_Links extends TestOfDoku_Parser { - + function TestOfDoku_Parser_Links() { $this->UnitTestCase('TestOfDoku_Parser_Links'); } - - + + function testExternalLinkSimple() { $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $this->P->parse("Foo http://www.google.com Bar"); @@ -22,7 +22,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testExternalLinkCase() { $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $this->P->parse("Foo HTTP://WWW.GOOGLE.COM Bar"); @@ -37,7 +37,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testExternalLinkJavascript() { $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $this->P->parse("Foo javascript:alert('XSS'); Bar"); @@ -50,7 +50,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testExternalWWWLink() { $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $this->P->parse("Foo www.google.com Bar"); @@ -65,7 +65,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testExternalFTPLink() { $this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $this->P->parse("Foo ftp.sunsite.com Bar"); @@ -81,8 +81,8 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } function testEmail() { -/* $this->fail('The emaillink mode seems to cause php 5.0.5 to segfault'); - return; //FIXME: is this still true?*/ +/* $this->fail('The emaillink mode seems to cause php 5.0.5 to segfault'); + return; //FIXME: is this still true?*/ $this->P->addMode('emaillink',new Doku_Parser_Mode_Emaillink()); $this->P->parse("Foo <bugs@php.net> Bar"); $calls = array ( @@ -96,7 +96,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInternalLinkOneChar() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[l]] Bar"); @@ -111,7 +111,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInternalLinkNamespaceNoTitle() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[foo:bar]] Bar"); @@ -126,7 +126,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInternalLinkNamespace() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|Test]] Bar"); @@ -141,7 +141,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInternalLinkSectionRef() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[wiki:syntax#internal|Syntax]] Bar"); @@ -156,7 +156,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testExternalInInternalLink() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[http://www.google.com|Google]] Bar"); @@ -171,7 +171,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInterwikiLink() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[iw>somepage|Some Page]] Bar"); @@ -186,7 +186,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInterwikiLinkCase() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[IW>somepage|Some Page]] Bar"); @@ -201,7 +201,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testInterwikiPedia() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[wp>Callback_(computer_science)|callbacks]] Bar"); @@ -216,7 +216,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testCamelCase() { $this->P->addMode('camelcaselink',new Doku_Parser_Mode_CamelCaseLink()); $this->P->parse("Foo FooBar Bar"); @@ -231,7 +231,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testFileLink() { $this->P->addMode('filelink',new Doku_Parser_Mode_FileLink()); $this->P->parse('Foo file://temp/file.txt Bar'); @@ -246,7 +246,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testFileLinkInternal() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse('Foo [[file://temp/file.txt|Some File]] Bar'); @@ -261,7 +261,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testWindowsShareLink() { $this->P->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); $this->P->parse('Foo \\\server\share Bar'); @@ -276,7 +276,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testWindowsShareLinkInternal() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse('Foo [[\\\server\share|My Documents]] Bar'); @@ -291,7 +291,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternal() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{img.gif}} Bar'); @@ -306,7 +306,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaNotImage() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar'); @@ -321,7 +321,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternalLAlign() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{img.gif }} Bar'); @@ -336,7 +336,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternalRAlign() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{ img.gif}} Bar'); @@ -351,7 +351,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternalCenter() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{ img.gif }} Bar'); @@ -366,7 +366,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternalParams() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{img.gif?50x100nocache}} Bar'); @@ -381,7 +381,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInternalTitle() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{img.gif?50x100|Some Image}} Bar'); @@ -396,7 +396,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaExternal() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{http://www.google.com/img.gif}} Bar'); @@ -411,7 +411,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaExternalParams() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{http://www.google.com/img.gif?50x100nocache}} Bar'); @@ -426,7 +426,7 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaExternalTitle() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{http://www.google.com/img.gif?50x100|Some Image}} Bar'); @@ -442,11 +442,11 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaInInternalLink() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|{{img.gif?10x20nocache|Some Image}}]] Bar"); - + $image = array( 'type'=>'internalmedia', 'src'=>'img.gif', @@ -455,9 +455,9 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { 'width'=>10, 'height'=>20, 'cache'=>'nocache', - 'linking'=>'details', + 'linking'=>'details', ); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -469,11 +469,11 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + function testMediaNoImageInInternalLink() { $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); $this->P->parse("Foo [[x:1:y:foo_bar:z|{{foo.txt?10x20nocache|Some Image}}]] Bar"); - + $image = array( 'type'=>'internalmedia', 'src'=>'foo.txt', @@ -482,9 +482,9 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { 'width'=>10, 'height'=>20, 'cache'=>'nocache', - 'linking'=>'details', + 'linking'=>'details', ); - + $calls = array ( array('document_start',array()), array('p_open',array()), @@ -496,7 +496,34 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ); $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } - + + function testMediaInEmailLink() { + $this->P->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $this->P->parse("Foo [[foo@example.com|{{img.gif?10x20nocache|Some Image}}]] Bar"); + + $image = array( + 'type'=>'internalmedia', + 'src'=>'img.gif', + 'title'=>'Some Image', + 'align'=>NULL, + 'width'=>10, + 'height'=>20, + 'cache'=>'nocache', + 'linking'=>'details', + ); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('emaillink',array('foo@example.com',$image)), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); + } + function testNestedMedia() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{img.gif|{{foo.gif|{{bar.gif|Bar}}}}}} Bar'); diff --git a/_test/cases/inc/parser/xhtml_links.test.php b/_test/cases/inc/parser/xhtml_links.test.php new file mode 100644 index 000000000..6582d33d8 --- /dev/null +++ b/_test/cases/inc/parser/xhtml_links.test.php @@ -0,0 +1,41 @@ +<?php +require_once DOKU_INC.'inc/parser/xhtml.php'; + +class xhtml_links_test extends UnitTestCase { + + function test_emaillink(){ + global $conf; + $conf['mailguard'] = 'visible'; + + $p = new Doku_Renderer_xhtml(); + $p->emaillink('foo@example.com','<script>alert(\'"alert"\');</script>'); + + $expect = '<a href="mailto:foo%20%5Bat%5D%20example%20%5Bdot%5D%20com" class="mail JSnocheck" title="foo [at] example [dot] com"><script>alert(\'"alert"\');</script></a>'; + + $this->assertEqual($p->doc,$expect); + } + + function test_emaillink_with_media(){ + global $conf; + $conf['mailguard'] = 'visible'; + + $image = array( + 'type'=>'internalmedia', + 'src'=>'img.gif', + 'title'=>'Some Image', + 'align'=>NULL, + 'width'=>10, + 'height'=>20, + 'cache'=>'nocache', + 'linking'=>'details', + ); + + $p = new Doku_Renderer_xhtml(); + $p->emaillink('foo@example.com',$image); + + $expect = '<a href="mailto:foo%20%5Bat%5D%20example%20%5Bdot%5D%20com" class="media JSnocheck" title="foo [at] example [dot] com"><img src="./lib/exe/fetch.php/img.gif?w=10&h=20&cache=nocache" class="media" title="Some Image" alt="Some Image" width="10" height="20" /></a>'; + + $this->assertEqual($p->doc,$expect); + } + +} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index c56367f47..4e8927679 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -672,8 +672,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['style'] = ''; $link['more'] = ''; - //we just test for image here - we need to encode the title our self - $this->_getLinkTitle($name, $address, $isImage); + $name = $this->_getLinkTitle($name, $address, $isImage); if ( !$isImage ) { $link['class']='mail JSnocheck'; } else { @@ -683,11 +682,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $address = $this->_xmlEntities($address); $address = obfuscate($address); $title = $address; + if(empty($name)){ $name = $address; - }else{ - $name = $this->_xmlEntities($name); } +#elseif($isImage{ +# $name = $this->_xmlEntities($name); +# } if($conf['mailguard'] == 'visible') $address = rawurlencode($address); |