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

 
 

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

Submitted by:  Christian von Schultz <schultz>
Submitted on:  Thu 27 Feb 2003 02:55:40 PM UTC  
 
Category: BugSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 2 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Sun 09 Mar 2003 05:12:05 PM UTCpawalStatusNone=>(Error - Not Found)
  Open/ClosedOpen=>(Error - Not Found)

Back to the top


Powered by Savane 3.1-cleanup1