Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25513

Windows: Ti.Utils.base64encode behaves different between Android/iOS and Windows

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 3.2.0
    • Fix Version/s: Release 7.5.0
    • Component/s: Windows
    • Labels:
    • Environment:

      Titanium SDK: 2.0.1GA2
      Platform OS: iOS

    • Story Points:
      5
    • Sprint:
      2018 Sprint 08 SDK, 2018 Sprint 15 SDK, 2016 Sprint 17 SDK, 2018 Sprint 18 SDK, 2018 Sprint 19 SDK, 2018 Sprint 20 SDK, 2018 Sprint 21

      Description

      Problem

      The result of Ti.Utils.base64encode is different between iOS and Android. On iOS there are newline characters included when the string is long enough, on Android the newline characters are stripped out (which is the correct way to do base64 UTF8 encoding). Please see the attached screenshot explaining the issue.

      Sample Code

       
      (function() {
          
          var win = Ti.UI.createWindow({backgroundColor:'white'});
          win.open();
          var shortString = 'ABCDEFGHIJ1234567890ABCDEFGHIJ12|psndemo2|abcd:1';
          var longString  = 'ABCDEFGHIJ1234567890ABCDEFGHIJ12|psndemo2|abcd:12345678901234567890';
          var tiBase64ShortResult = Ti.Utils.base64encode(shortString);
          var tiBase64LongResult  = Ti.Utils.base64encode(longString);
       
          tiBase64ShortResult = String(tiBase64ShortResult);
          tiBase64LongResult = String(tiBase64LongResult);
       
       
           // BUG #2: Run this code in iOS and Android and compare the results
          // On iOS we get newline characters. On Android the newline characters are stripped out.
          // The correct behavior for UTF8 base64 encoding is to strip out the newline characters. 
          // Android's implementation is correct.
          tiBase64ShortResult = tiBase64ShortResult.replace(/\r\n/g,"***NEWLINE***");
          tiBase64LongResult  = tiBase64LongResult.replace(/\r\n/g,"***NEWLINE***");
          var alertDialog = Titanium.UI.createAlertDialog(
          {
              title: 'Result', 
              message: 'short: ' + tiBase64ShortResult + '\nlong: ' + tiBase64LongResult, buttonNames: ['OK','Cancel'] 
          });
          alertDialog.show();
      })();
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kiguchi Kota Iguchi
                Reporter:
                vjoshi Varun Joshi
                Reviewer:
                Gary Mathews
                Tester:
                Keerthi Mahalingam
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-5975
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code