From 0d1438e0fb5b17d65f15e1cf0f235af6185b56e9 Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Tue, 1 Oct 2019 22:01:42 -0700 Subject: [PATCH 1/8] Start to make "path" be a first class property of ResBundle --- js/lib/ResBundle.js | 11 +++++++++-- js/lib/ilib.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/lib/ResBundle.js b/js/lib/ResBundle.js index d542085088..3d2cff2434 100644 --- a/js/lib/ResBundle.js +++ b/js/lib/ResBundle.js @@ -70,6 +70,10 @@ var IString = require("./IString.js"); * * The default behaviour is the same as before, which is to return the source string * unchanged. + * + *
  • path - look in the given path for the resource bundle files. This can be + * an absolute path or a relative path that is relative to the application's root. + * Default: "resources". * *
  • onLoad - a callback function to call when the resources are fully * loaded. When the onLoad option is given, this class will attempt to @@ -223,6 +227,7 @@ var ResBundle = function (options) { this.loadParams = {}; this.missing = "source"; this.sync = true; + this.path = "resources"; if (options) { if (options.locale) { @@ -250,6 +255,9 @@ var ResBundle = function (options) { this.missing = options.missing; } } + if (options.path) { + this.path = options.path; + } } else { options = {sync: true}; } @@ -257,14 +265,13 @@ var ResBundle = function (options) { this.map = {}; lookupLocale = this.locale.isPseudo() ? new Locale("en-US") : this.locale; - var object = "ResBundle-" + this.baseName; Utils.loadData({ - object: object, locale: lookupLocale, name: this.baseName + ".json", sync: this.sync, loadParams: this.loadParams, + root: this.path, callback: ilib.bind(this, function (map) { if (!map) { map = ilib.data[this.baseName] || {}; diff --git a/js/lib/ilib.js b/js/lib/ilib.js index 07cb519d36..c0841d2795 100644 --- a/js/lib/ilib.js +++ b/js/lib/ilib.js @@ -460,7 +460,7 @@ ilib.Loader = function() {}; * or resources, then that data can be lazy loaded dynamically when it is * needed by calling this method. Each ilib class will first * check for the existence of data under ilib.data, and if it is not there, - * it will attempt to load it by calling this method of the laoder, and then place + * it will attempt to load it by calling this method of the loader, and then place * it there.

    * * Suggested implementations of this method might load files From 1feea7874b5c94d35cfbc5456e2567f34adb888e Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Wed, 2 Oct 2019 16:11:15 -0700 Subject: [PATCH 2/8] Added "basePath" and unit tests basePath property added to ResBundle constructor so that it becomes a first-class property. It specifies a directory to look in for your resource files. Added unit tests that show how attempting to load two resource files with the same name but in different directories fails. --- js/lib/Loader.js | 7 ++-- js/lib/ResBundle.js | 12 +++---- js/lib/Utils.js | 13 ++++--- js/test/root/testresources.js | 57 +++++++++++++++++++++++++++++- js/test/root/testresourcesasync.js | 33 ++++++++++++++++- 5 files changed, 106 insertions(+), 16 deletions(-) diff --git a/js/lib/Loader.js b/js/lib/Loader.js index 01f56c624b..9cdb5598b7 100644 --- a/js/lib/Loader.js +++ b/js/lib/Loader.js @@ -1,7 +1,7 @@ /* * Loader.js - shared loader implementation * - * Copyright © 2015, 2018, JEDLSoft + * Copyright © 2015, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,8 +86,9 @@ Loader.prototype._loadFileAlongIncludePath = function(includePath, pathname) { return undefined; }; -Loader.prototype.loadFiles = function(paths, sync, params, callback) { - var includePath = params && params.base ? [params.base].concat(this.includePath) : this.includePath; +Loader.prototype.loadFiles = function(paths, sync, params, callback, root) { + root = root || (params && params.base); + var includePath = root ? [root].concat(this.includePath) : this.includePath; //console.log("Loader loadFiles called"); // make sure we know what we can load diff --git a/js/lib/ResBundle.js b/js/lib/ResBundle.js index 3d2cff2434..f81977c3ab 100644 --- a/js/lib/ResBundle.js +++ b/js/lib/ResBundle.js @@ -1,7 +1,7 @@ /* * ResBundle.js - Resource bundle definition * - * Copyright © 2012-2016, 2018, JEDLSoft + * Copyright © 2012-2016, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,9 +71,10 @@ var IString = require("./IString.js"); * The default behaviour is the same as before, which is to return the source string * unchanged. * - *

  • path - look in the given path for the resource bundle files. This can be + *
  • basePath - look in the given path for the resource bundle files. This can be * an absolute path or a relative path that is relative to the application's root. - * Default: "resources". + * Default if this is not specified is to look in the standard path (ie. in the root + * of the app). * *
  • onLoad - a callback function to call when the resources are fully * loaded. When the onLoad option is given, this class will attempt to @@ -227,7 +228,6 @@ var ResBundle = function (options) { this.loadParams = {}; this.missing = "source"; this.sync = true; - this.path = "resources"; if (options) { if (options.locale) { @@ -255,9 +255,7 @@ var ResBundle = function (options) { this.missing = options.missing; } } - if (options.path) { - this.path = options.path; - } + this.path = options.basePath; } else { options = {sync: true}; } diff --git a/js/lib/Utils.js b/js/lib/Utils.js index 0f1706c1bd..57d8bfc837 100644 --- a/js/lib/Utils.js +++ b/js/lib/Utils.js @@ -1,7 +1,7 @@ /* * Utils.js - Core utility routines * - * Copyright © 2012-2015, 2018, JEDLSoft + * Copyright © 2012-2015, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -311,14 +311,14 @@ Utils.getLocFiles = function(locale, name) { * @static * @private */ -Utils._callLoadData = function (files, sync, params, callback) { +Utils._callLoadData = function (files, sync, params, root, callback) { // console.log("Utils._callLoadData called"); if (typeof(ilib._load) === 'function') { // console.log("Utils._callLoadData: calling as a regular function"); return ilib._load(files, sync, params, callback); } else if (typeof(ilib._load) === 'object' && typeof(ilib._load.loadFiles) === 'function') { // console.log("Utils._callLoadData: calling as an object"); - return ilib._load.loadFiles(files, sync, params, callback); + return ilib._load.loadFiles(files, sync, params, callback, root); } // console.log("Utils._callLoadData: not calling. Type is " + typeof(ilib._load) + " and instanceof says " + (ilib._load instanceof Loader)); @@ -360,6 +360,9 @@ function dataNotExists(basename, pathname) { *
  • replace - boolean. When merging json objects, this parameter controls whether to merge arrays * or have arrays replace each other. If true, arrays in child objects replace the arrays in parent * objects. When false, the arrays in child objects are concatenated with the arrays in parent objects. + *
  • root - String. If provided, look in this root directory first for files, and then fall back + * to the standard include paths if they are not found in this root. If not provided, just search the + * standard include paths. *
  • loadParams - Object. An object with parameters to pass to the loader function *
  • sync - boolean. Whether or not to load the data synchronously *
  • callback - function(?)=. callback Call back function to call when the data is available. @@ -378,6 +381,7 @@ Utils.loadData = function(params) { callback = undefined, nonlocale = false, replace = false, + root, basename; if (!params || typeof(params.callback) !== 'function') { @@ -406,6 +410,7 @@ Utils.loadData = function(params) { replace = params.replace; } + root = params.root; callback = params.callback; if (!type) { @@ -448,7 +453,7 @@ Utils.loadData = function(params) { })); if (files.length) { - Utils._callLoadData(files, sync, loadParams, ilib.bind(this, function(arr) { + Utils._callLoadData(files, sync, loadParams, root, ilib.bind(this, function(arr) { for (var i = 0; i < files.length; i++) { if (arr[i]) { var localeBits = files[i].split("\/").slice(0, -1).join('_'); diff --git a/js/test/root/testresources.js b/js/test/root/testresources.js index be245d6629..6d268097c6 100644 --- a/js/test/root/testresources.js +++ b/js/test/root/testresources.js @@ -1,7 +1,7 @@ /* * testresources.js - test the Resources object * - * Copyright © 2012-2015, 2017-2018, JEDLSoft + * Copyright © 2012-2015, 2017-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,9 @@ if (typeof(ResBundle) === "undefined") { if (typeof(Locale) === "undefined") { var Locale = require("../../lib/Locale.js"); } +if (ilib._getPlatform() === "nodejs" && ilib._dyndata && ilib._dyncode) { + var path = require("path"); +} ilib.data.strings = { "first string": "first", @@ -2072,6 +2075,58 @@ module.exports.testresources = { "dritte String 2" ]); + test.done(); + }, + + testResBundleGetStringWithBasePath: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // clear this to be sure it is actually loading something + ilib.clearCache(); + + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources")); + + var rb = new ResBundle({ + locale: "ja-JP", + name: "basetest", + basePath: base + }); + + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "{country}からこんにちは"); + test.equal(rb.getString("Hello from {city}").toString(), "{city}からこんにちは"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "{city}と{country}からこんにちは"); + test.done(); + }, + + testResBundleGetStringWithDifferentBasePath: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // don't clear the cache + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources2")); + + var rb = new ResBundle({ + locale: "ja-JP", + name: "basetest", + basePath: base + }); + + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "{country}からこんにちは2"); + test.equal(rb.getString("Hello from {city}").toString(), "{city}からこんにちは2"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "{city}と{country}からこんにちは2"); test.done(); } }; \ No newline at end of file diff --git a/js/test/root/testresourcesasync.js b/js/test/root/testresourcesasync.js index c370506a01..88026283a2 100644 --- a/js/test/root/testresourcesasync.js +++ b/js/test/root/testresourcesasync.js @@ -1,7 +1,7 @@ /* * testresourcesasync.js - test the Resources object * - * Copyright © 2018, JEDLSoft + * Copyright © 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,38 @@ module.exports.testresourcesasync = { test.done(); } }); + }, + + testResBundleAsyncGetStringWithPathesMX: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // clear this to be sure it is actually loading something + ilib.data.strings = undefined; + ilib.data.strings_es = undefined; + ilib.data.strings_und_MX = undefined; + ilib.data.strings_es_MX = undefined; + ilib.clearCache(); + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources")); + + new ResBundle({ + locale: "es-MX", + sync: false, + basePath: base, + onLoad: function(rb) { + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "Que tal de {country}"); + test.equal(rb.getString("Hello from {city}").toString(), "Que tal de {city}"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "Hola de {city} en {country}"); + test.done(); + } + }); }, testResBundleAsyncGetStringOtherBundlePsuedoRaw: function(test) { From ad23102465ea4bfe1b185c8940cf591b408ae947 Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Thu, 3 Oct 2019 23:40:12 -0700 Subject: [PATCH 3/8] Use the root dir in the property name of data - standardize the way that the ilib.data property name is generated - use this property name everywhere ilib.data is accessed - use the root/base dir in the property name so that two files with the same name and locale but in different dirs will not be loading to the same property name --- js/lib/NormString.js | 2 +- js/lib/Utils.js | 46 ++++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/js/lib/NormString.js b/js/lib/NormString.js index 4e144921e8..3128f3e4db 100644 --- a/js/lib/NormString.js +++ b/js/lib/NormString.js @@ -141,7 +141,7 @@ NormString.init = function(options) { if (files.length) { //console.log("loading files " + JSON.stringify(files)); - Utils._callLoadData(files, sync, loadParams, function(arr) { + Utils._callLoadData(files, sync, loadParams, undefined, function(arr) { for (var i = 0; i < arr.length; i++) { if (typeof(arr[i]) !== 'undefined') { ilib.extend(ilib.data.norm[toLoad[i]], arr[i]); diff --git a/js/lib/Utils.js b/js/lib/Utils.js index 57d8bfc837..6adf94219a 100644 --- a/js/lib/Utils.js +++ b/js/lib/Utils.js @@ -25,6 +25,26 @@ var ISet = require("./ISet.js"); var Utils = {}; +/** + * Return the property name inside of ilib.data that corresponds to the given locale data file. + * + * @private + * @param {String} basename the basename of the file + * @param {String} pathname the path from the root to the base file which usually encodes the + * locale of the file + * @param {String=} root the root directory of the file or undefined for the standard locale dir + */ +function getPropertyName(basename, pathname, root) { + var bits = [ basename ]; + if (root) { + bits = bits.concat(root.split("\/")); + } + if (pathname) { + bits = bits.concat(pathname.split("\/")); + } + return bits.join('_'); +} + /** * Return an array of locales that represent the sublocales of * the given locale. These sublocales are intended to be used @@ -182,9 +202,10 @@ Utils.getSublocales = function(locale) { * If false, concatenate array elements in object1 with items in object2. * @param {boolean=} returnOne if true, only return the most locale-specific data. If false, * merge all the relevant locale data together. + * @param {string=} root root path if there is one * @return {Object?} the merged locale data */ -Utils.mergeLocData = function (prefix, locale, replaceArrays, returnOne) { +Utils.mergeLocData = function (prefix, locale, replaceArrays, returnOne, root) { var data = undefined; var loc = locale || new Locale(); var mostSpecific; @@ -194,7 +215,7 @@ Utils.mergeLocData = function (prefix, locale, replaceArrays, returnOne) { mostSpecific = data; Utils.getSublocales(loc).forEach(function(l) { - var property = (l === "root") ? prefix : prefix + '_' + l.replace(/-/g, "_"); + var property = getPropertyName(prefix, (l === "root") ? undefined : l.replace(/-/g, "/"), root); if (ilib.data[property]) { if (returnOne) { @@ -325,6 +346,11 @@ Utils._callLoadData = function (files, sync, params, root, callback) { return undefined; }; +function getPropertyNameFromFile(basename, filepath, root) { + var dir = Path.dirname(filepath); + return getPropertyName(basename, (dir === "." || dir === "/" || dir === "..") ? undefined : dir, root); +} + /** * Return true if the locale data corresponding to the given pathname is not already loaded * or assembled. @@ -334,11 +360,8 @@ Utils._callLoadData = function (files, sync, params, root, callback) { * @param locale * @returns */ -function dataNotExists(basename, pathname) { - var localeBits = pathname.split("\/").slice(0, -1).join('_'); - var property = localeBits ? basename + '_' + localeBits : basename; - - return !ilib.data[property]; +function dataNotExists(basename, pathname, root) { + return !ilib.data[getPropertyNameFromFile(basename, pathname, root)]; } /** @@ -449,15 +472,14 @@ Utils.loadData = function(params) { // find the ones we haven't loaded before files = files.filter(ilib.bind(this, function(file) { - return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file); + return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file, root); })); if (files.length) { Utils._callLoadData(files, sync, loadParams, root, ilib.bind(this, function(arr) { for (var i = 0; i < files.length; i++) { if (arr[i]) { - var localeBits = files[i].split("\/").slice(0, -1).join('_'); - var property = !nonlocale && localeBits ? basename + '_' + localeBits : basename; + var property = nonlocale ? basename : getPropertyNameFromFile(basename, files[i], root); if (!ilib.data[property]) { ilib.data[property] = arr[i]; @@ -467,7 +489,7 @@ Utils.loadData = function(params) { } if (!nonlocale) { - data = Utils.mergeLocData(basename, locale, replace, returnOne); + data = Utils.mergeLocData(basename, locale, replace, returnOne, root); if (ilib._cacheMerged) ilib.data.cache.merged[spec] = data; } else { data = ilib.data[basename]; @@ -483,7 +505,7 @@ Utils.loadData = function(params) { // No loader, or data already loaded? Then use whatever data we have already in ilib.data if (!nonlocale) { - data = Utils.mergeLocData(basename, locale, replace, returnOne); + data = Utils.mergeLocData(basename, locale, replace, returnOne, root); if (ilib._cacheMerged) ilib.data.cache.merged[spec] = data; } else { data = ilib.data[basename]; From 27ab6b2a2a837776365d31ae69678b91502ae964 Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Thu, 3 Oct 2019 23:48:16 -0700 Subject: [PATCH 4/8] Added release notes --- docs/ReleaseNotes.md | 5 +++++ js/lib/ResBundle.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 40a763c8a6..e79cefaa21 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -16,6 +16,11 @@ part of the locale specifier if it has a very common/default value Bug Fixes: * Fixed unit test failures which occur on QT 5.12 +* Fixed problem where two resource bundle files with the same name and same locale but loaded from +different directories were cached in the same place. + * Introduced the new "basePath" property to ResBundle constructor to specify which directory + to load the resource bundle from. This property is used to differentiate files loaded from + different directories. Build 006 ------- diff --git a/js/lib/ResBundle.js b/js/lib/ResBundle.js index f81977c3ab..8735b715a7 100644 --- a/js/lib/ResBundle.js +++ b/js/lib/ResBundle.js @@ -70,7 +70,7 @@ var IString = require("./IString.js"); * * The default behaviour is the same as before, which is to return the source string * unchanged. - * + * *
  • basePath - look in the given path for the resource bundle files. This can be * an absolute path or a relative path that is relative to the application's root. * Default if this is not specified is to look in the standard path (ie. in the root From 093cb3ba565abf7bf3a6a1004c4528161ed7bffd Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Thu, 3 Oct 2019 23:52:24 -0700 Subject: [PATCH 5/8] Need these test data files --- js/test/root/resources/ja/basetest.json | 6 ++++++ js/test/root/resources2/ja/basetest.json | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 js/test/root/resources/ja/basetest.json create mode 100644 js/test/root/resources2/ja/basetest.json diff --git a/js/test/root/resources/ja/basetest.json b/js/test/root/resources/ja/basetest.json new file mode 100644 index 0000000000..2049bb2aa7 --- /dev/null +++ b/js/test/root/resources/ja/basetest.json @@ -0,0 +1,6 @@ +{ + "hello" : "こんにちは", + "Hello from {country}": "{country}からこんにちは", + "Hello from {city}": "{city}からこんにちは", + "Greetings from {city} in {country}": "{city}と{country}からこんにちは" +} diff --git a/js/test/root/resources2/ja/basetest.json b/js/test/root/resources2/ja/basetest.json new file mode 100644 index 0000000000..72622f469c --- /dev/null +++ b/js/test/root/resources2/ja/basetest.json @@ -0,0 +1,6 @@ +{ + "hello" : "こんにちは2", + "Hello from {country}": "{country}からこんにちは2", + "Hello from {city}": "{city}からこんにちは2", + "Greetings from {city} in {country}": "{city}と{country}からこんにちは2" +} From 7bd268b25871091d853dd628db54f3fde1809cdc Mon Sep 17 00:00:00 2001 From: Goun Lee Date: Tue, 8 Oct 2019 15:45:57 +0900 Subject: [PATCH 6/8] Modify code to work with enact use case.. --- js/lib/ResBundle.js | 5 ++++- js/lib/Utils.js | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/js/lib/ResBundle.js b/js/lib/ResBundle.js index 8735b715a7..be4e814f62 100644 --- a/js/lib/ResBundle.js +++ b/js/lib/ResBundle.js @@ -242,6 +242,7 @@ var ResBundle = function (options) { this.type = options.type; } this.lengthen = options.lengthen || false; + this.path = options.basePath; if (typeof(options.sync) !== 'undefined') { this.sync = !!options.sync; @@ -249,13 +250,15 @@ var ResBundle = function (options) { if (typeof(options.loadParams) !== 'undefined') { this.loadParams = options.loadParams; + if (typeof (options.loadParams.root) !== 'undefined') { + this.path = options.loadParams.root; + } } if (typeof(options.missing) !== 'undefined') { if (options.missing === "pseudo" || options.missing === "empty") { this.missing = options.missing; } } - this.path = options.basePath; } else { options = {sync: true}; } diff --git a/js/lib/Utils.js b/js/lib/Utils.js index 6adf94219a..1302e55019 100644 --- a/js/lib/Utils.js +++ b/js/lib/Utils.js @@ -472,7 +472,11 @@ Utils.loadData = function(params) { // find the ones we haven't loaded before files = files.filter(ilib.bind(this, function(file) { - return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file, root); + if (typeof root !== 'undefined') { + return dataNotExists(basename, file, root); + } else { + return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file, root); + } })); if (files.length) { From 93faa1fb3990270b46c6e14c35fdb6aad3b0faa6 Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Wed, 9 Oct 2019 23:17:07 -0700 Subject: [PATCH 7/8] Resolve the file name cache fix differently If you don't check the fileSet cache, then it will attempt to load the same missing json files every time. That is, if a json file does not exist for a locale, then attempting to load it will fail, and nothing stops it from trying again and again to load that same missing file every time it is requested. --- js/lib/Utils.js | 8 ++------ js/test/util/testutils.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/js/lib/Utils.js b/js/lib/Utils.js index 1302e55019..011297158b 100644 --- a/js/lib/Utils.js +++ b/js/lib/Utils.js @@ -472,11 +472,7 @@ Utils.loadData = function(params) { // find the ones we haven't loaded before files = files.filter(ilib.bind(this, function(file) { - if (typeof root !== 'undefined') { - return dataNotExists(basename, file, root); - } else { - return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file, root); - } + return !ilib.data.cache.fileSet.has(Path.join(root, file)) && dataNotExists(basename, file, root); })); if (files.length) { @@ -489,7 +485,7 @@ Utils.loadData = function(params) { ilib.data[property] = arr[i]; } } - ilib.data.cache.fileSet.add(files[i]); + ilib.data.cache.fileSet.add(Path.join(root, files[i])); } if (!nonlocale) { diff --git a/js/test/util/testutils.js b/js/test/util/testutils.js index 8c706f5a77..7693eaf7b7 100644 --- a/js/test/util/testutils.js +++ b/js/test/util/testutils.js @@ -1,7 +1,7 @@ /* * testutils.js - test the utility routines * - * Copyright © 2012-2015, 2017-2018 JEDLSoft + * Copyright © 2012-2015, 2017-2019 JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2031,6 +2031,36 @@ module.exports.testutils = { } }, + testLoadDataDontMixDifferentBasePaths: function(test) { + ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined; + ilib.setLoaderCallback(mockLoaderNoMulti); + try { + Utils.loadData({ + name: "foo.json", + locale: "de-DE", + basePath: "asdf", + callback: function (results) { + test.ok(results); + Utils.loadData({ + name: "foo.json", + locale: "de-DE", + basePath: "foobar", + callback: function (results2) { + // if there is a cache miss when it attempts to load a file from disk twice + // then the mock loader will throw an exception, which is expected here + // because the base paths are different and Utils.loadData should try to + // load two files with the same name but different bases. + test.fail(); + test.done(); + } + }); + } + }); + } catch (e) { + test.done(); + } + }, + testLoadDataCacheResultAlreadyMerged: function(test) { ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined; ilib.setLoaderCallback(mockLoaderNoMulti); From f98cdcfcc767cdc87ba6e1ce413fe1f8504dd83b Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Thu, 10 Oct 2019 07:16:23 -0700 Subject: [PATCH 8/8] Update copyright years in header comment ... only for those files that were changed in this PR. --- js/lib/NormString.js | 2 +- js/lib/ilib.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/lib/NormString.js b/js/lib/NormString.js index 3128f3e4db..3051c6dc59 100644 --- a/js/lib/NormString.js +++ b/js/lib/NormString.js @@ -1,7 +1,7 @@ /* * NormString.js - ilib normalized string subclass definition * - * Copyright © 2013-2015, 2018, JEDLSoft + * Copyright © 2013-2015, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/js/lib/ilib.js b/js/lib/ilib.js index c0841d2795..e2f1f6806d 100644 --- a/js/lib/ilib.js +++ b/js/lib/ilib.js @@ -1,7 +1,7 @@ /* * ilib.js - define the ilib name space * - * Copyright © 2012-2018, JEDLSoft + * Copyright © 2012-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.