bugGnuheter - Bugs: bug #2667, ampersand() i mainfile.php...

 
 

bug #2667: ampersand() i mainfile.php använder felaktig algoritm

Submitter:  Christian von Schultz <schultz>
Submitted:  Thu 27 Feb 2003 02:55:40 PM UTC
   
 
Category:  Bug Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 27 Feb 2003 02:55:40 PM UTC, original submission:  


Så här ser funktionen ampersand() ut i sitt nuvarande skick:
function ampersand($str) {
$str = ereg_replace('&', '&amp;', $str);
$str = ereg_replace('&amp;([a-z]+;)', '&\\1', $str);

return $str;
}

Uppenbart vill man tillåta HTML-entities, men man är allt för restriktiv. Även &Auml; för stora Ä eller &frac14; för en fjärdedel utesluts, vilket även skrivsätt som &#xE6; (æ) och andra görs.

Föreslagen lösning:
function ampersand($str) {
  $str = str_replace("&", "&amp;", $str);
  $str = eregi_replace("&amp;(#x?[0-9a-f]+;)", "&\\1", $str);
  $str = eregi_replace("&amp;([a-z][a-z0-9]+;)", "&\\1", $str);

  return $str;
}

Skilnaden är dels case-sensitive, dels att även &#x14B; (fonetiskt ng-tecken som i "ring") och &frac34; (tre fjärdedelar) tillåts.

Buggar i den nya algoritmen: även &#15B; tillåts, trots att hexadecimala tal kräver ett x framför; och att den är lite för restriktiv gällande entities av typen &sup3; (upphöjd trea) som enligt XML-standarden även får innehålla bindestreck, punkter, med mera. Ingen av de i HTML 4 definierade entities gör detta, vilket borde göra mitt antagande säkert.

Christian von Schultz <schultz>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2003-03-09 pawal StatusNone None
    Open/ClosedOpen None

Back to the top

Powered by Savane 3.13-caa5.
Corresponding source code