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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 2.0.1, Release 3.1.0, Release 3.2.0
    • Fix Version/s: Release 7.0.0
    • Component/s: iOS
    • Environment:

      Titanium SDK: 2.0.1GA2
      Platform OS: iOS

    • Story Points:
      5
    • Sprint:
      2017 Sprint 02 SDK

      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:
                hknoechel Hans Knöchel
                Reporter:
                vjoshi Varun Joshi
                Reviewer:
                Vijay Singh
                Tester:
                Abir Mukherjee
              • Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Source Code