From 5b78e30d9f51b43449e797c1edc97de97129bf20 Mon Sep 17 00:00:00 2001 From: bermiferrer Date: Fri, 5 Oct 2007 12:29:15 +0000 Subject: [PATCH] Fixing bug produced by mail_to which badly escaped UTF-8 characters when using javascript encryption git-svn-id: http://svn.akelos.org/trunk@381 a2fa5c27-f921-0410-a72c-bf682d381be0 --- lib/AkActionView/helpers/url_helper.php | 4 +- test/unit/lib/AkActionView/helpers/url_helper.php | 130 ++++++++++++---------- 2 files changed, 71 insertions(+), 63 deletions(-) rewrite test/unit/lib/AkActionView/helpers/url_helper.php (84%) diff --git a/lib/AkActionView/helpers/url_helper.php b/lib/AkActionView/helpers/url_helper.php index 02ae46c..62c48c3 100644 --- a/lib/AkActionView/helpers/url_helper.php +++ b/lib/AkActionView/helpers/url_helper.php @@ -244,8 +244,8 @@ class UrlHelper $html_options = Ak::delete($html_options, 'cc','bcc','subject','body','encode'); if ($encode == 'javascript'){ - $tmp = "document.write('".TagHelper::content_tag('a', $name, array_merge($html_options,array('href' => 'mailto:'.$email_address.$extras )))."');"; - for ($i=0;$i 'mailto:'.$email_address.$extras )))."');"; + for ($i=0; $i < strlen($tmp); $i++){ $string.='%'.dechex(ord($tmp[$i])); } return ""; diff --git a/test/unit/lib/AkActionView/helpers/url_helper.php b/test/unit/lib/AkActionView/helpers/url_helper.php dissimilarity index 84% index 7beebdd..9d6f854 100755 --- a/test/unit/lib/AkActionView/helpers/url_helper.php +++ b/test/unit/lib/AkActionView/helpers/url_helper.php @@ -1,61 +1,69 @@ -setReturnValue('urlFor', '/url/for/test'); - //$Controller->setReturnValue('_getCompleteRequestUri','/url/for/test'); - - $url = new UrlHelper(); - $url->setController($Controller); - - $this->assertReference($Controller, $url->_controller); - - - $input = array('disabled'=>1,'checked'=>false,'selected'=>''); - $expected = array('disabled'=>'disabled'); - $this->assertEqual($url->_convert_boolean_attributes($input, array('disabled','checked','selected')),$expected); - - $input = array('disabled'=>true,'id'=>'hithere'); - $expected = array('disabled'=>'disabled','id'=>'hithere'); - $this->assertEqual($url->_convert_boolean_attributes($input, 'disabled'),$expected); - - $this->assertEqual($url->url_for(array('action'=>'create')),'/url/for/test'); - - $this->assertEqual($url->button_to('Edit'), - '
'. - '
'); - - - $this->assertEqual($url->link_to('Delete this page', array('action' => 'destroy', 'id' => 3), array('confirm' => 'Are you sure?')),'Delete this page'); - $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true)),'Help'); - $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true, 'confirm' => 'Are you sure?')),'Help'); - $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('post' => true)),'Help'); - $this->assertEqual($url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'Destroy account'); - - $this->assertEqual($url->link_to_unless(true,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),''); - $this->assertEqual($url->link_to_unless(false,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'Destroy account'); - $this->assertEqual($url->_popup_javascript_function('A'),'window.open(this.href);'); - $this->assertEqual($url->_popup_javascript_function(array('A','B','C')),'window.open(this.href,\'A\',\'C\');'); - - $this->assertEqual($url->_confirm_javascript_function('Are you sure?'),'confirm(\'Are you sure?\')'); - - - $this->assertEqual($url->mail_to('me@domain.com', 'My email', array('cc' => 'ccaddress@domain.com', 'bcc' => 'bccaddress@domain.com', 'subject' => 'This is an example email', 'body' => 'This is the body of the message.')),'My email'); - $this->assertEqual($url->mail_to('me@domain.com', 'My email', array('encode' => 'javascript')),''); - $this->assertEqual($url->mail_to('me@domain.com', 'My email', array('encode' => 'hex')),'My email'); - - } -} - -ak_test('UrlHelperTests'); - -?> \ No newline at end of file +Controller = &new MockAkActionController($this); + $this->Controller->setReturnValue('urlFor', '/url/for/test'); + //$this->Controller->setReturnValue('_getCompleteRequestUri','/url/for/test'); + + $this->url = new UrlHelper(); + $this->url->setController($this->Controller); + } + + function test_for_UrlHelper() + { + $this->assertReference($this->Controller, $this->url->_controller); + + + $input = array('disabled'=>1,'checked'=>false,'selected'=>''); + $expected = array('disabled'=>'disabled'); + $this->assertEqual($this->url->_convert_boolean_attributes($input, array('disabled','checked','selected')),$expected); + + $input = array('disabled'=>true,'id'=>'hithere'); + $expected = array('disabled'=>'disabled','id'=>'hithere'); + $this->assertEqual($this->url->_convert_boolean_attributes($input, 'disabled'),$expected); + + $this->assertEqual($this->url->url_for(array('action'=>'create')),'/url/for/test'); + + $this->assertEqual($this->url->button_to('Edit'), + '
'. + '
'); + + + $this->assertEqual($this->url->link_to('Delete this page', array('action' => 'destroy', 'id' => 3), array('confirm' => 'Are you sure?')),'Delete this page'); + $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('popup' => true)),'Help'); + $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('popup' => true, 'confirm' => 'Are you sure?')),'Help'); + $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('post' => true)),'Help'); + $this->assertEqual($this->url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'Destroy account'); + + $this->assertEqual($this->url->link_to_unless(true,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),''); + $this->assertEqual($this->url->link_to_unless(false,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'Destroy account'); + $this->assertEqual($this->url->_popup_javascript_function('A'),'window.open(this.href);'); + $this->assertEqual($this->url->_popup_javascript_function(array('A','B','C')),'window.open(this.href,\'A\',\'C\');'); + + $this->assertEqual($this->url->_confirm_javascript_function('Are you sure?'),'confirm(\'Are you sure?\')'); + + + $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('cc' => 'ccaddress@domain.com', 'bcc' => 'bccaddress@domain.com', 'subject' => 'This is an example email', 'body' => 'This is the body of the message.')),'My email'); + $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('encode' => 'javascript')),''); + $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('encode' => 'hex')),'My email'); + + } + + function test_should_encode_utf8_characters_as_entities_when_encoding_mail_to_links() + { + $escaped_iacute = '%26%69%61%63%75%74%65%3b'; + $this->assertTrue(strstr($this->url->mail_to('test@example.com', 'mounstro de pulsa aquĆ­', array('encode' => 'javascript')), $escaped_iacute)); + } +} + +ak_test('UrlHelperTests'); + +?> \ No newline at end of file -- 2.11.4.GIT