|
From: creedon <icr...@us...> - 2005-09-05 16:38:20
|
Update of /cvsroot/frontierkernel/odbs/frontierRoot/system/verbs/builtins/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30590 Modified Files: entityDecode Log Message: when flAlphaEntities is true undo what enityEncode did in reverse order, the old code wasn't able to decode simple urls in attribute values Index: entityDecode =================================================================== RCS file: /cvsroot/frontierkernel/odbs/frontierRoot/system/verbs/builtins/xml/entityDecode,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** entityDecode 26 Mar 2005 19:44:15 -0000 1.1.1.1 --- entityDecode 5 Sep 2005 16:38:11 -0000 1.2 *************** *** 1,3 **** FrontierVcsFile:1:scpt:system.verbs.builtins.xml.entityDecode ! on entityDecode (s, flAlphaEntities = false, flSkipMalformedEntities = false, flDecodeHexEntities = false) { ÇChanges -- the flipside of xml.entityEncode Ç8/16/04; 4:07:17 PM by JES ÇNew optional parameter, flDecodeHexEntities. If true, then entities in the form, &x2A; will be decoded to their equivalent character. ÇDefault is false, preserving existing behavior. Ç12/12/01; 2:47:54 AM by JES ÇNew optional parameter, flSkipMalformedEntities. If true, then malformed numerical entities which either contain non-numeric characters or which lack an ending semicolon character don't cause an error. They're passed through as-is. Ç10/22/99; 3:35:56 PM by DW Çdecode &#xxx; to the equivalent ASCII character. Ç11/14/2000; 5:44:31 PM by DW Çxml.entityDecode now takes an optional boolean parameter, default value false, that says whether "alpha" entities are decoded. This is necessary to avoid breakage. The four entities are: < > & " Ç11/29/01; 6:56:06 PM by PBS ÇSkip entities > 255, since they can't be decoded into characters. local (ix, ixremainder, numstring, ixsemi, remainder = s); loop { ixremainder = string.patternMatch ("&#", remainder); if ixremainder == 0 { break}; ix = ixremainder + (sizeof (s) - sizeof (remainder)); numstring = ""; ixsemi = sizeof (s); for i = ix + 2 to sizeof (s) { if s [i] == ';' { ixsemi = i; break}; numstring = numstring + s [i]}; local (num, flMalformed = false); try { num = number (numstring)} else { //hex entity or malformed if flDecodeHexEntities { //JES 8/16/04: decode hex entities if numstring[1] == "x" { try { num = number ("0" + numstring)} else { flMalformed = true}} else { if flAlphaEntities { //decode alpha entities inline with numeric entities to prevent double-decoding case numstring { "amp" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("&", s, ix)}; "lt" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("<", s, ix)}; "gt" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert (">", s, ix)}; "quot" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("\"", s, ix)}} else { flMalformed = true}} else { flMalformed = true}}} else { flMalformed = true}}; if flSkipMalformedEntities and flMalformed { remainder = string.mid (s, ix + 1, infinity); continue}; if num < 256 { //PBS //11/29/01: skip large entities s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert (char (num), s, ix)}; remainder = string.mid (s, ix + 1, infinity)}; bundle { //decode alpha entities if flAlphaEntities and (not flDecodeHexEntities) { ÇJES 8/19/04: If flDecodeHexEntities is true, alpha-entities are decoded inline with numeric entities. Prevents double-decoding. s = string.replaceall (s, "<", "<"); s = string.replaceall (s, ">", ">"); s = string.replaceall (s, "&", "&"); s = string.replaceall (s, """, "\"")}}; return (s)}; Çbundle //test code Çxml.entityDecode ("Oh the <buzzing> of the bees & the "sycamore" trees.", true) Çxml.entityDecode ("A’PB") Çxml.entityDecode (xml.entityEncode ("Olejováø skvrna na \"Labi\"zøejmì do <Nìmecka> & nedoplujeøíjna 1999 13:49"), true) Çxml.entityDecode ("{Hello}", flSkipMalformedEntities:true) Ç"{Hello}" Çxml.entityDecode ("{Hello}", flSkipMalformedEntities:false) //should be an error \ No newline at end of file --- 1,3 ---- FrontierVcsFile:1:scpt:system.verbs.builtins.xml.entityDecode ! on entityDecode (s, flAlphaEntities = false, flSkipMalformedEntities = false, flDecodeHexEntities = false) { ÇChanges Ç8/1/05; 11:56:58 PM by TAC Çwhen flAlphaEntities is true undo what enityEncode did in reverse order, the old code wasn't able to decode simple urls in attribute values Çold code order Çs = string.replaceAll (s, "<", "<") Çs = string.replaceAll (s, ">", ">") Çs = string.replaceAll (s, "&", "&") Çs = string.replaceAll (s, """, "\"") Çnew code order Çs = string.replaceAll (s, """, "\"") Çs = string.replaceAll (s, "&", "&") Çs = string.replaceAll (s, ">", ">") Çs = string.replaceAll (s, "<", "<") Ç8/16/04; 4:07:17 PM by JES ÇNew optional parameter, flDecodeHexEntities. If true, then entities in the form, &x2A; will be decoded to their equivalent character. ÇDefault is false, preserving existing behavior. Ç12/12/01; 2:47:54 AM by JES ÇNew optional parameter, flSkipMalformedEntities. If true, then malformed numerical entities which either contain non-numeric characters or which lack an ending semicolon character don't cause an error. They're passed through as-is. Ç10/22/99; 3:35:56 PM by DW Çdecode &#xxx; to the equivalent ASCII character. Ç11/14/2000; 5:44:31 PM by DW Çxml.entityDecode now takes an optional boolean parameter, default value false, that says whether "alpha" entities are decoded. This is necessary to avoid breakage. The four entities are: < > & " Ç11/29/01; 6:56:06 PM by PBS ÇSkip entities > 255, since they can't be decoded into characters. Çthe flipside of xml.entityEncode local (ix, ixremainder, numstring, ixsemi, remainder = s); loop { ixremainder = string.patternMatch ("&#", remainder); if ixremainder == 0 { break}; ix = ixremainder + (sizeof (s) - sizeof (remainder)); numstring = ""; ixsemi = sizeof (s); for i = ix + 2 to sizeof (s) { if s [i] == ';' { ixsemi = i; break}; numstring = numstring + s [i]}; local (num, flMalformed = false); try { num = number (numstring)} else { //hex entity or malformed if flDecodeHexEntities { //JES 8/16/04: decode hex entities if numstring[1] == "x" { try { num = number ("0" + numstring)} else { flMalformed = true}} else { if flAlphaEntities { //decode alpha entities inline with numeric entities to prevent double-decoding case numstring { "amp" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("&", s, ix)}; "lt" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("<", s, ix)}; "gt" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert (">", s, ix)}; "quot" { s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert ("\"", s, ix)}} else { flMalformed = true}} else { flMalformed = true}}} else { flMalformed = true}}; if flSkipMalformedEntities and flMalformed { remainder = string.mid (s, ix + 1, infinity); continue}; if num < 256 { //PBS //11/29/01: skip large entities s = string.delete (s, ix, ixsemi - ix + 1); s = string.insert (char (num), s, ix)}; remainder = string.mid (s, ix + 1, infinity)}; bundle { //decode alpha entities if flAlphaEntities and (not flDecodeHexEntities) { ÇJES 8/19/04: If flDecodeHexEntities is true, alpha-entities are decoded inline with numeric entities. Prevents double-decoding. s = string.replaceAll (s, """, "\""); s = string.replaceAll (s, "&", "&"); s = string.replaceAll (s, ">", ">"); s = string.replaceAll (s, "<", "<")}}; return (s)}; Çbundle //test code Çxml.entityDecode ("Oh the <buzzing> of the bees & the "sycamore" trees.", true) Çxml.entityDecode (xml.entityEncode ("Olejováø skvrna na \"Labi\"zøejmì do <Nìmecka> & nedoplujeøíjna 1999 13:49"), true) Çxml.entityDecode ("{Hello}", flSkipMalformedEntities:true) Ç"{Hello}" Çxml.entityDecode ("{Hello}", flSkipMalformedEntities:false) //should be an error \ No newline at end of file |