Ignore:
Timestamp:
Dec 20, 2006 9:06:33 AM (6 years ago)
Author:
thomasb
Message:

New (strict) quoting for all kind of strings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/main.inc

    r403 r419  
    735735  $framed = $GLOBALS['_framed']; 
    736736  $command = sprintf("display_message('%s', '%s');", 
    737                      rep_specialchars_output(rcube_label(array('name' => $message, 'vars' => $vars)), 'js'), 
     737                     JQ(rcube_label(array('name' => $message, 'vars' => $vars))), 
    738738                     $type); 
    739739                      
     
    855855                                $JS_OBJECT_NAME, 
    856856                                $name, 
    857                                 rep_specialchars_output(rcube_label($name), 'js')));   
     857                                JQ(rcube_label($name)))); 
    858858  } 
    859859 
     
    898898 
    899899 
    900 // convert a string from one charset to another 
    901 // this function is not complete and not tested well 
     900/** 
     901 * Convert a string from one charset to another. 
     902 * Uses mbstring and iconv functions if possible 
     903 * 
     904 * @param  string Input string 
     905 * @param  string Suspected charset of the input string 
     906 * @param  string Target charset to convert to; defaults to $GLOBALS['CHARSET'] 
     907 * @return Converted string 
     908 */ 
    902909function rcube_charset_convert($str, $from, $to=NULL) 
    903910  { 
     
    954961 
    955962 
    956  
    957 // replace specials characters to a specific encoding type 
     963/** 
     964 * Replacing specials characters to a specific encoding type 
     965 * 
     966 * @param  string  Input string 
     967 * @param  string  Encoding type: text|html|xml|js|url 
     968 * @param  string  Replace mode for tags: show|replace|remove 
     969 * @param  boolean Convert newlines 
     970 * @return The quoted string 
     971 */ 
    958972function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE) 
    959973  { 
    960974  global $OUTPUT_TYPE, $OUTPUT; 
    961   static $html_encode_arr, $js_rep_table, $rtf_rep_table, $xml_rep_table; 
     975  static $html_encode_arr, $js_rep_table, $xml_rep_table; 
    962976 
    963977  if (!$enctype) 
     
    10011015    } 
    10021016 
    1003  
    10041017  if ($enctype=='url') 
    10051018    return rawurlencode($str); 
    10061019 
    1007  
    1008   // if the replace tables for RTF, XML and JS are not yet defined 
     1020  // if the replace tables for XML and JS are not yet defined 
    10091021  if (!$js_rep_table) 
    10101022    { 
    1011     $js_rep_table = $rtf_rep_table = $xml_rep_table = array(); 
     1023    $js_rep_tabl = $xml_rep_table = array(); 
    10121024    $xml_rep_table['&'] = '&'; 
    10131025 
     
    10151027      { 
    10161028      $hex = dechex($c); 
    1017       $rtf_rep_table[Chr($c)] = "\\'$hex"; 
    10181029      $xml_rep_table[Chr($c)] = "&#$c;"; 
    10191030       
     
    10261037    } 
    10271038 
    1028   // encode for RTF 
     1039  // encode for XML 
    10291040  if ($enctype=='xml') 
    10301041    return strtr($str, $xml_rep_table); 
     
    10391050    } 
    10401051 
    1041   // encode for RTF 
    1042   if ($enctype=='rtf') 
    1043     return preg_replace("/\r\n/", "\par ", strtr($str, $rtf_rep_table)); 
    1044  
    10451052  // no encoding given -> return original string 
    10461053  return $str; 
     1054  } 
     1055 
     1056/** 
     1057 * Quote a given string. Alias function for rep_specialchars_output 
     1058 * @see rep_specialchars_output 
     1059 */ 
     1060function Q($str, $mode='strict', $newlines=TRUE) 
     1061  { 
     1062  return rep_specialchars_output($str, 'html', $mode, $newlines); 
     1063  } 
     1064 
     1065/** 
     1066 * Quote a given string. Alias function for rep_specialchars_output 
     1067 * @see rep_specialchars_output 
     1068 */ 
     1069function JQ($str, $mode='strict', $newlines=TRUE) 
     1070  { 
     1071  return rep_specialchars_output($str, 'js', $mode, $newlines); 
    10471072  } 
    10481073 
     
    12491274    case 'label': 
    12501275      if ($attrib['name'] || $attrib['command']) 
    1251         return rep_specialchars_output(rcube_label($attrib)); 
     1276        return Q(rcube_label($attrib)); 
    12521277      break; 
    12531278 
     
    13321357        { 
    13331358        $name = !empty($CONFIG['product_name']) ? $CONFIG['product_name'] : 'RoundCube Webmail'; 
    1334         return rep_specialchars_output($name, 'html', 'all'); 
     1359        return Q($name); 
    13351360        } 
    13361361      else if ($object=='version') 
     
    13541379          $title .= ucfirst($task); 
    13551380           
    1356         return rep_specialchars_output($title, 'html', 'all'); 
     1381        return Q($title); 
    13571382        } 
    13581383 
     
    14201445  // get localized text for labels and titles 
    14211446  if ($attrib['title']) 
    1422     $attrib['title'] = rep_specialchars_output(rcube_label($attrib['title'])); 
     1447    $attrib['title'] = Q(rcube_label($attrib['title'])); 
    14231448  if ($attrib['label']) 
    1424     $attrib['label'] = rep_specialchars_output(rcube_label($attrib['label'])); 
     1449    $attrib['label'] = Q(rcube_label($attrib['label'])); 
    14251450 
    14261451  if ($attrib['alt']) 
    1427     $attrib['alt'] = rep_specialchars_output(rcube_label($attrib['alt'])); 
     1452    $attrib['alt'] = Q(rcube_label($attrib['alt'])); 
    14281453 
    14291454  // set title to alt attribute for IE browsers 
     
    15381563 
    15391564  foreach ($a_show_cols as $col) 
    1540     $table .= '<td class="'.$col.'">' . rep_specialchars_output(rcube_label($col)) . "</td>\n"; 
     1565    $table .= '<td class="'.$col.'">' . Q(rcube_label($col)) . "</td>\n"; 
    15411566 
    15421567  $table .= "</tr></thead>\n<tbody>\n"; 
    15431568   
    15441569  $c = 0; 
    1545  
    15461570  if (!is_array($table_data))  
    15471571    { 
     
    15551579      foreach ($a_show_cols as $col) 
    15561580        { 
    1557         $cont = rep_specialchars_output($sql_arr[$col]); 
    1558             $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1581        $cont = Q($sql_arr[$col]); 
     1582        $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
    15591583        } 
    15601584 
     
    15741598      foreach ($a_show_cols as $col) 
    15751599        { 
    1576         $cont = rep_specialchars_output($row_data[$col]); 
    1577             $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1600        $cont = Q($row_data[$col]); 
     1601        $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
    15781602        } 
    15791603 
Note: See TracChangeset for help on using the changeset viewer.