Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6003] Android/iOS : decodeURIComponent() method not working

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNot Our Bug
Resolution Date2018-12-10T11:29:56.000+0000
Affected Version/sAppcelerator Studio 4.4.2
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandoid, decode, ios
ReporterJignesh Kasundra
AssigneeShak Hossain
Created2018-11-01T09:40:47.000+0000
Updated2018-12-10T11:29:56.000+0000

Description

I'm trying to display equivalent text for the below string but it's not working

var win = Ti.UI.createWindow({
	backgroundColor : 'white'
});

win.open();

alert(decodeURIComponent('Hello – World'));

the resulted text should be >> Hello – World

Comments

  1. Michael Gangolf 2018-11-01

    That doesn't work in Javascript. Run the alert(decodeURIComponent('Hello – World')); in the Firefox developer tools and you will see the same text. The proper encoded version would be: decodeURIComponent('Hello%20%E2%80%93%20World') Try to run the "normal" text through encodeURIComponent to see the correct URI text. And if you are using Alloy/underscore you can use https://underscorejs.org/#unescape to unescape the HTML entities
  2. Jignesh Kasundra 2018-11-01

    Hi Michael i have tryed to encode the character in Titanium using encodeURIComponent('Hello – World') method and got the below result Hello%20%26%238211%20World and got the correct result on browser by decodeURIComponent() method but while using in Titanium it's returning the back to same character *Hello – World* how to i implement this with titanium ? i am using titanium classic project in my app i am getting *Hello – World* as original string thanks.
  3. Michael Gangolf 2018-11-01

    Again, you are using it wrong:
       var enc = encodeURIComponent("Hello – World");
       var dec = decodeURIComponent(enc);
       console.log(enc);
       console.log(dec);
       
    outputs the correct result in Ti 7.4.1 (Android) Hello – World is not an URLComponent text. It is a HTML entities text. And you would need to use either a Webview or underscore (or something else from https://stackoverflow.com/questions/5796718/html-entity-decode) to decode it
  4. Jignesh Kasundra 2018-11-01

    so my problem is i am getting *Hello – World* as original string and in the titanium label control have to print Hello – World is there anyway to implement this ?
  5. Michael Gangolf 2018-11-01

    Either change your API that it will send proper strings or search for decoding HTML entities -> text in Javascript (e.g. https://stackoverflow.com/questions/17678694/replace-html-entities-e-g-8217-with-character-equivalents-when-parsing-an). So this is not a bug and better be asked in TiSlack or Stackoverflow. There are even modules you'll find on google: https://github.com/appcelerator-forks/kosso.TiHTML or something like this
       var decodeHtmlEntity = function(str) {
         return str.replace(/&#(\d+);/g, function(match, dec) {
           return String.fromCharCode(dec);
         });
       };
       decodeHtmlEntity("Hello – World")
       
  6. Nazmus Salahin 2018-12-01

    Hello [~jignesh.igp], Just passing as update here.Are you able to get that sorted out? Please let us know if you need help with this issue. Thanks
  7. Rakhi Mitro 2018-12-10

    Hello, I just wanted to follow up with you about this issue? Are you still experiencing this problem? Please let us know if you need more help with this issue. Thanks
  8. Jignesh Kasundra 2018-12-10

    Hello, my issue is resolved. please close the issue Thanks

JSON Source