0

I am generating a url (for facebook dialog) from flash:

var lvs_url = "http://www.facebook.com/dialog/feed?app_id=208524139202627&name=š š&caption=&description=&link=http://apps.facebook.com/celjska_puzzle&redirect_uri=http://apps.facebook.com/celjska_puzzle/"
var lvo_req : URLRequest = new URLRequest( lvs_url ) ;
navigateToURL( lvo_req , "_blank" );

but by the time that url makes it to the browser, the š's have been turned into %9A's, which then show up as ?-diamond's in the facebook pop up.

However, the browser is ok with %20's

here is the encoded url: http://www.facebook.com/dialog/feed?app_id=208524139202627&name=%9A%20%9A&caption=&description=&link=http://apps.facebook.com/celjska_puzzle&redirect_uri=http://apps.facebook.com/celjska_puzzle/

dsdsdsdsd
  • 2,880
  • 6
  • 41
  • 56
  • `0x9A` is not valid UTF-8 byte sequence. How did you create it? It should be `%C5%A1` for `š` – Esailija Jul 15 '12 at 13:54
  • it was apparently created by the flash AS3 **var lvo_req : URLRequest = new URLRequest( lvs_url )** because it was a **š** going in, but a **%9A** by the time it got to the browser address bar – dsdsdsdsd Jul 15 '12 at 14:07

1 Answers1

0

Try encodeURIComponent:

var lvs_url = "http://www.facebook.com/dialog/feed?app_id=208524139202627&name="+encodeURIComponent("š š")+"&caption=&description=&link=http://apps.facebook.com/celjska_puzzle&redirect_uri=http://apps.facebook.com/celjska_puzzle/";
var lvo_req : URLRequest = new URLRequest( lvs_url ) ;
navigateToURL( lvo_req , "_blank" );

From [docs](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#URLRequest()) :

Creates a URLRequest object.

If System.useCodePage is true, the request is encoded using the system code page, rather than Unicode.

If System.useCodePage is false, the request is encoded using Unicode, rather than the system code page.

Specification says:

Non-ASCII characters must first be encoded according to UTF-8 [STD63], and then each octet of the corresponding UTF-8 sequence must be percent- encoded to be represented as URI characters.

This means that "š" must be encoded as %C5%A1 in urls. Try setting System.useCodePage to false, even though the documentation is ambiguous because encoded using Unicode doesn't necessarily mean UTF-8.

I should also mention that your file should be saved in UTF-8 encoding if you are literally using "š" in the file.

Community
  • 1
  • 1
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • **1** - _System.useCodePage = false_ ... did not help **2** - _Non-ASCII characters must first be encoded according to UTF-8 [STD63], and then each octet of the corresponding UTF-8 sequence must be percent- encoded to be represented as URI characters._ ... I'm sorry but I have no idea what this means **3** - _This means that "š" must be encoded as %C5%A1_ ... when I literally put that into a browser address bar it worked, but of course my urls are being built dynamically in flash with all sorts of characters, so I can't hardcode. – dsdsdsdsd Jul 15 '12 at 18:46
  • @dsdsdsdsd can you clarify, did it change anything at all? Or do you mean it was already at false. Have you saved your file in UTF-8? – Esailija Jul 15 '12 at 18:47
  • my flash Edit/Preferences/Actionscript/open-import and save-export are set to utf-8. ... Right now I am reading about URLRequest.contentType ... – dsdsdsdsd Jul 15 '12 at 18:52
  • @dsdsdsdsd Do you mean you still got `%9A` after setting `System.useCodePage` to `false`? – Esailija Jul 15 '12 at 19:00
  • @dsdsdsdsd I just found out that AS3 should have the function `encodeURIComponent` (same as javascript), you can try that – Esailija Jul 15 '12 at 19:03
  • _encodeURI_ worked ... if you will make this into an answer I can 'check' it ... ... ... EDIT: oh I see you already did. – dsdsdsdsd Jul 15 '12 at 19:10