From 3c73bf32f8ff04b057eeb65a86ef29d3d0cd0d1b Mon Sep 17 00:00:00 2001 From: James Keshavarzi Date: Tue, 20 Nov 2012 16:21:49 -0500 Subject: [PATCH] Fixing issue where locale information for name/description was incorrectly case sensitive Issue - blackberry/BB10-Webworks-Packager#214 Reviewed By: Jeffrey Heifetz Tested By: Tracy Li --- Framework | 2 +- lib/config-parser.js | 2 +- test/unit/lib/config-parser.js | 48 +++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Framework b/Framework index 06370a2..9d756e5 160000 --- a/Framework +++ b/Framework @@ -1 +1 @@ -Subproject commit 06370a2b59fca88fb25bc4128a3ffc7628ca398b +Subproject commit 9d756e5f29e2df4ed0aafbe3672e773a784d5f4a diff --git a/lib/config-parser.js b/lib/config-parser.js index 35f2489..d22ffb4 100644 --- a/lib/config-parser.js +++ b/lib/config-parser.js @@ -507,7 +507,7 @@ function processLocalizedText(tag, data, widgetConfig) { if (attribs) { language = attribs['xml:lang'] || DEFAULT; - widgetConfig[tag][language] = tagElement['#']; + widgetConfig[tag][language.toLowerCase()] = tagElement['#']; } else { widgetConfig[tag][DEFAULT] = tagElement; } diff --git a/test/unit/lib/config-parser.js b/test/unit/lib/config-parser.js index 301844a..cd916e4 100644 --- a/test/unit/lib/config-parser.js +++ b/test/unit/lib/config-parser.js @@ -141,7 +141,7 @@ describe("config parser", function () { it("Fails when no name was provided - multiple elements", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ["", - { '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'FR' } }, + { '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'fr' } }, ]; mockParsing(data); @@ -154,7 +154,7 @@ describe("config parser", function () { it("Fails when localized name was provided but empty", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ["API Smoke Test", - { '#': '', '@': { 'xml:lang': 'FR' } }, + { '#': '', '@': { 'xml:lang': 'fr' } }, ]; mockParsing(data); @@ -177,33 +177,44 @@ describe("config parser", function () { it("Parses a name element with xml:lang - single element", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); - data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } }; + data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } }; mockParsing(data); configParser.parse(configPath, session, extManager, function (configObj) { - expect(configObj.name).toEqual({"EN": "EN VALUE"}); + expect(configObj.name).toEqual({"en": "EN VALUE"}); + }); + }); + + it("Parses a name element that is not case sensitive", function () { + var data = testUtilities.cloneObj(testData.xml2jsConfig); + data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } }; + + mockParsing(data); + + configParser.parse(configPath, session, extManager, function (configObj) { + expect(configObj.name).toEqual({"en": "EN VALUE"}); }); }); it("Parses a name element with xml:lang - multi element", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ['API Smoke Test', - { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } }, - { '#': 'FR VALUE', '@': { 'xml:lang': 'FR' } } + { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } }, + { '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } } ]; mockParsing(data); configParser.parse(configPath, session, extManager, function (configObj) { - expect(configObj.name).toEqual({"default": "API Smoke Test", "EN": "EN VALUE", "FR": "FR VALUE"}); + expect(configObj.name).toEqual({"default": "API Smoke Test", "en": "EN VALUE", "fr": "FR VALUE"}); }); }); it("Fails when localized name was provided but empty", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ['API Smoke Test', - { '#': '', '@': { 'xml:lang': 'FR' } }, + { '#': '', '@': { 'xml:lang': 'fr' } }, ]; mockParsing(data); @@ -226,26 +237,37 @@ describe("config parser", function () { it("Parses a description element with xml:lang - single element", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); - data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } }; + data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } }; + + mockParsing(data); + + configParser.parse(configPath, session, extManager, function (configObj) { + expect(configObj.description).toEqual({"en": "EN VALUE"}); + }); + }); + + it("Parses a description element that is not case sensitive", function () { + var data = testUtilities.cloneObj(testData.xml2jsConfig); + data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } }; mockParsing(data); configParser.parse(configPath, session, extManager, function (configObj) { - expect(configObj.description).toEqual({"EN": "EN VALUE"}); + expect(configObj.description).toEqual({"en": "EN VALUE"}); }); }); it("Parses a description element with xml:lang - multi element", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.description = ['This is my app', - { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } }, - { '#': 'FR VALUE', '@': { 'xml:lang': 'FR' } } + { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } }, + { '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } } ]; mockParsing(data); configParser.parse(configPath, session, extManager, function (configObj) { - expect(configObj.description).toEqual({"default": "This is my app", "EN": "EN VALUE", "FR": "FR VALUE"}); + expect(configObj.description).toEqual({"default": "This is my app", "en": "EN VALUE", "fr": "FR VALUE"}); }); });