You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/03/12 15:56:59 UTC

git commit: Fix ConfigParser.getPreference error + tests

Repository: cordova-cli
Updated Branches:
  refs/heads/master 6fae83eb0 -> 3f448d9f6


Fix ConfigParser.getPreference error + tests

Was getting the following error:

    ReferenceError: a is not defined
        at Object.ConfigParser.getPreference
            (/home/alfred/repos/cordova-cli/src/ConfigParser.js:88:23)

github: close #138


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/3f448d9f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/3f448d9f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/3f448d9f

Branch: refs/heads/master
Commit: 3f448d9f64d0fef85fd1044c38bb3e48a2fdf808
Parents: 6fae83e
Author: Farid Neshat <Fa...@yahoo.com>
Authored: Wed Mar 12 20:44:15 2014 +0800
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 12 10:56:03 2014 -0400

----------------------------------------------------------------------
 spec/ConfigParser.spec.js | 8 ++++++++
 src/ConfigParser.js       | 8 ++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3f448d9f/spec/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/spec/ConfigParser.spec.js b/spec/ConfigParser.spec.js
index da05ef8..1faec88 100644
--- a/spec/ConfigParser.spec.js
+++ b/spec/ConfigParser.spec.js
@@ -72,5 +72,13 @@ describe('config.xml parser', function () {
                 expect(cfg.name()).toEqual('this.is.bat.country');
             });
         });
+        describe('preference', function() {
+            it('should get value of existing preference', function() {
+                expect(cfg.getPreference('fullscreen')).toEqual('true');
+            });
+            it('should get undefined as non existing preference', function() {
+                expect(cfg.getPreference('zimzooo!')).toEqual(undefined);
+            });
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3f448d9f/src/ConfigParser.js
----------------------------------------------------------------------
diff --git a/src/ConfigParser.js b/src/ConfigParser.js
index eae230b..36adc0c 100644
--- a/src/ConfigParser.js
+++ b/src/ConfigParser.js
@@ -82,12 +82,12 @@ ConfigParser.prototype = {
     getPreference: function(name) {
         var preferences = this.doc.findall('preference');
         var ret = null;
-        for (var i = 0, ii = preferences.length; i < ii; ++i) {
+        preferences.forEach(function (preference) {
             // Take the last one that matches.
-            if (preferences[i].attrib.name.toLowerCase() === name) {
-                ret = a.attrib.value;
+            if (preference.attrib.name.toLowerCase() === name) {
+                ret = preference.attrib.value;
             }
-        }
+        });
         return ret;
     },
     write:function() {