Changeset 4401 in subversion


Ignore:
Timestamp:
Jan 10, 2011 8:22:45 AM (2 years ago)
Author:
alec
Message:
  • Fix handling square brackets in links (#1487672)
Location:
trunk/roundcubemail
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4396 r4401  
    1111- Add handling of multifolder METADATA/ANNOTATION responses 
    1212- Fix handling of INBOX when personal namespace prefix is non-empty (#1487657) 
     13- Fix handling square brackets in links (#1487672) 
    1314 
    1415RELEASE 0.5-RC 
  • trunk/roundcubemail/program/include/rcube_string_replacer.php

    r4142 r4401  
    3838    // Simplified domain expression for UTF8 characters handling 
    3939    $utf_domain = '[^?&@"\'\\/()\s\r\t\n]+\\.[a-z]{2,5}'; 
    40     $url = '[a-z0-9%=#@+?.:;&\\/_~-]+'; 
     40    $url = '[a-z0-9%=#@+?.:;&\\/_~\\[\\]-]+'; 
    4141 
    4242    $this->link_pattern = "/([\w]+:\/\/|\Wwww\.)($utf_domain($url)?)/i"; 
     
    8282    if (preg_match('!^(http|ftp|file)s?://!', $scheme)) { 
    8383      $url = $matches[1] . $matches[2]; 
    84       $i = $this->add(html::a(array('href' => $url, 'target' => '_blank'), Q($url))); 
    8584    } 
    8685    else if (preg_match('/^(\W)www\.$/', $matches[1], $m)) { 
    87       $url = 'www.' . $matches[2]; 
    88       $i = $this->add($m[1] . html::a(array('href' => 'http://' . $url, 'target' => '_blank'), Q($url))); 
     86      $url        = 'www.' . $matches[2]; 
     87      $url_prefix = 'http://'; 
     88      $prefix     = $m[1]; 
    8989    } 
     90 
     91    $suffix = $this->parse_url_brackets($url); 
     92    $i = $this->add($prefix . html::a(array( 
     93      'href' => $url_prefix . $url, 
     94      'target' => '_blank' 
     95      ), Q($url)) . $suffix); 
    9096 
    9197    // Return valid link for recognized schemes, otherwise, return the unmodified string for unrecognized schemes. 
     
    101107  public function mailto_callback($matches) 
    102108  { 
     109    $href   = $matches[1]; 
     110    $suffix = $this->parse_url_brackets($href); 
     111 
    103112    $i = $this->add(html::a(array( 
    104         'href' => 'mailto:' . $matches[1], 
    105         'onclick' => "return ".JS_OBJECT_NAME.".command('compose','".JQ($matches[1])."',this)", 
    106       ), 
    107       Q($matches[1]))); 
     113        'href' => 'mailto:' . $href, 
     114        'onclick' => "return ".JS_OBJECT_NAME.".command('compose','".JQ($href)."',this)", 
     115      ), Q($href)) . $suffix); 
    108116 
    109117    return $i >= 0 ? $this->get_replacement($i) : ''; 
     
    130138  } 
    131139 
     140  /** 
     141   * Fixes bracket characters in URL handling 
     142   */ 
     143  public static function parse_url_brackets(&$url) 
     144  { 
     145    // #1487672: special handling of square brackets, 
     146    // URL regexp allows [] characters in URL, for example: 
     147    // "http://example.com/?a[b]=c". However we need to handle 
     148    // properly situation when a bracket is placed at the end 
     149    // of the link e.g. "[http://example.com]" 
     150    if (preg_match('/(\\[|\\])/', $url)) { 
     151      $in = false; 
     152      for ($i=0, $len=strlen($url); $i<$len; $i++) { 
     153        if ($url[$i] == '[') { 
     154          if ($in) 
     155            break; 
     156          $in = true; 
     157        } 
     158        else if ($url[$i] == ']') { 
     159          if (!$in) 
     160            break; 
     161          $in = false; 
     162        } 
     163      } 
     164 
     165      if ($i<$len) { 
     166        $suffix = substr($url, $i); 
     167        $url    = substr($url, 0, $i); 
     168      } 
     169    } 
     170 
     171    return $suffix; 
     172  } 
     173 
    132174} 
  • trunk/roundcubemail/tests/mailfunc.php

    r4110 r4401  
    111111    $part->body = quoted_printable_decode(file_get_contents(TESTS_DIR . 'src/plainbody.txt')); 
    112112    $html = rcmail_print_body($part, array('safe' => true)); 
    113      
     113 
    114114    $this->assertPattern('/<a href="mailto:nobody@roundcube.net" onclick="return rcmail.command\(\'compose\',\'nobody@roundcube.net\',this\)">nobody@roundcube.net<\/a>/', $html, "Mailto links with onclick"); 
    115115    $this->assertPattern('#<a href="http://www.apple.com/legal/privacy/" target="_blank">http://www.apple.com/legal/privacy/</a>#', $html, "Links with target=_blank"); 
     116    $this->assertPattern('#\\[<a href="http://example.com/\\?tx\\[a\\]=5" target="_blank">http://example.com/\\?tx\\[a\\]=5</a>\\]#', $html, "Links with square brackets"); 
    116117  } 
    117118 
  • trunk/roundcubemail/tests/src/plainbody.txt

    r2323 r4401  
    3636https://myinfo.apple.com/cgi-bin/WebObjects/MyInfo 
    3737 
     38-[http://example.com/?tx[a]=5]- 
Note: See TracChangeset for help on using the changeset viewer.