p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Encoding and decoding


Message #1 by "Imar Spaanjaars" <Imar@S...> on Wed, 19 Sep 2001 10:14:08
Hi Alex,

Thanks for the code. Looks rather useful. 

In the mean time I also (re)discovered the undocumented Escape() and 
UnEscape() methods. I think however that I prefer your solution, 
because "Undocumented" might mean "not present in future versions".

Thanks again,

Imar




> Hi Imar, I had the same problem trying to pass illegal characters 
> through xmlhttp, I developed these client-side functions to handle it, 
you 
> could use the same regular expressions on the server
> 
> function convertCharsToEntities(s)
> {
> 	for(var i=0;i<s.length;i++){
> 	
> 		c = s.charCodeAt(i);
> 	
> 		if(c>255){
> 			var re = new RegExp(s.charAt(i));
> 			s = s.replace(re, "&#"+c+";");
> 		}
> 	}
> 	
> 	return(s);
> }
> function convertEntitiesToChars(s){
> 
> 	var re = /&#(\d{3,4});/;
> 
> 	while (s.search(re) > -1) {
> 	
> 		c = parseInt(RegExp.$1)
> 		s = s.replace(re, String.fromCharCode(c));
> 	
> 	}
> 	return(s);
> }
> 
> -----Original Message-----
> From: Imar Spaanjaars [mailto:Imar@S...]
> Sent: 19 September 2001 11:14
> To: Code Clinic
> Subject: [proasp_codeclinic] Encoding and decoding
> 
> 
> Hi there,
> 
> I have a security component that returns an encrypted session key which 
is
> saved as a cookie. The string could look like this:
> 
> Á¸&ê¡QƒäÑÓU=01!
> f—UíÙ‚À\5ºÛ=15=03-
> êJ =18ræ´1µÅK©‡9é6®&#
> 402;=19
> IFì,„?ÍU€á
> ”£Úm™±]¢
> 
> or like this:
> 
> =C1=B8&=EA=A1Qf=E4=D1=D3U=01!f-U=ED=D9'=C0\5=BA=DB=15=03-=EAJ 
> =18r=E6=B41=B5=C5K=A9?9=E96=AEf=19IF=EC,"?=CDUEUR=E1 
> "=A3=DAm(tm)=B1]=A2
> 
> (I am not sure how P2P will handle special characters. It might HTML
> encode my already encoded string. It should be the one that contains all
> kinds of weird characters, like the copyright sign).
> 
> However, the component returns the string unencoded, so sometimes it
> contains illegal characters that cannot be saved to a cookie. In that
> case, everything after the illegal character is simply skipped.
> 
> I can of course HTML-encode the string, so it contains only legal stuff 
> 
> that I can display and save as a cookie
> 
> But, how do I convert this back so the string can be used in another 
> COM+ component again?
> 
> Do I have other options than using HTML-encode to encode and decode my
> string so I can save it as a legal cookie??
> 
> Thanks in advance for any suggestions

  Return to Index