Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-11223

Better check for date validity of contact.birthday / Fix: RangeError Invalid Date

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • None
    • Desktop Firefox & Safari
      Android & iOS Webview

    Description

      The issue: on Safari & iOS webview if we perform a toJSON() on a instanceof Date object which is a 'Invalid Date' object, that throws an error. This does not happen on Firefox & Chrome!

      I encountered this issue while sending device contacts over socket.io which iterates over contacts props and does a toJSON(), but the problem was that the Date object from birthday property was not valid.

      Simple test case:

      var contact = { birthday: null }; //data provided by cordova-plugin-contacts
      
      try {
          contact.birthday = new Date(parseFloat(contact.birthday));
      }
      catch(e) {
         console.log(e); //this will never be called
      }
      
      //where the error occures..
      contact.birthday.toJSON();
      

      An 'Invalid Date' error does not throw anything, so a simple try-catch block doesn't pass the validity of that date.

      The changes I made in convertUtils.js resolves this problem.

      Attachments

        Activity

          People

            Unassigned Unassigned
            TanaseButcaru Tanase Butcaru
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: