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

Incorrect way of trying to XHR the cordova_plugins.json file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.7.0
    • None
    • cordova-js
    • None

    Description

      Frankly, I don't like the way you are trying to XHR the cordova_plugins.json file asynchronously (lines 6811-6831 in cordova-2.7.0.js).
      Why there is no check:

      cordova-2.7.0.js
        xhr.onload = function() {
          if (xhr.readyState === 4) {
            if (xhr.status === 200) {
              ....
              handlePluginsObject(obj);
            } else {
              finishPluginLoading();
            }
          }
        }
         ....
      

      For instance, if there is no cordova_plugins.json jetty server will send a responce with the following responceText:

       
      "<html>
      <head>
      <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
      <title>Error 404 Not Found</title>
      </head>
      <body>
      <h2>HTTP ERROR: 404</h2>
      <p>Problem accessing /cordova_plugins.json. Reason:
      <pre>    Not Found</pre></p>
      <hr /><i><small>Powered by Jetty://</small></i>
      </body>
      </html>"
      

      And JSON.parse will throw "SyntaxError: Unexpected token <", which won't be caught - app will crash

      Attachments

        Issue Links

          Activity

            People

              agrieve Andrew Grieve
              ibuziuk Ilya Buziuk
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: