From cc8a09dd83a7217596aa6054021d1f0427cff570 Mon Sep 17 00:00:00 2001 From: Miyuki Hanaoka Date: Tue, 12 Feb 2019 18:33:51 +0900 Subject: [PATCH 1/4] fix ReferenceError: function paramter name and variable name when throwing error are not the same --- .../org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js b/scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js index 9aa22fde5..4736e619c 100644 --- a/scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js +++ b/scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js @@ -102,7 +102,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseDate : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -117,7 +117,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseTime : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -133,7 +133,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:time pattern.'); + throw new Error('Value [' + text + '] does not match the xs:time pattern.'); }, parseTimezoneString : function(text) { // (('+' | '-') hh ':' mm) | 'Z' @@ -156,7 +156,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { var minute = parseInt(results[5], 10); return sign * (hour * 60 + minute); } - throw new Error('Value [' + value + '] does not match the timezone pattern.'); + throw new Error('Value [' + text + '] does not match the timezone pattern.'); } }, print : function(value, context, output, scope) { From 1ef32aee935f6d6b97a6b0b473a3c36ab6ed370a Mon Sep 17 00:00:00 2001 From: Miyuki Hanaoka Date: Wed, 13 Feb 2019 17:20:22 +0900 Subject: [PATCH 2/4] add tests for the case schema.xsd.calendar.parseXXX throw error --- .../hisrc/jsonix/test/JsonixSchemaXSDTest.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js b/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js index ac9328248..aeea37027 100644 --- a/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js +++ b/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js @@ -1,3 +1,17 @@ +function expectError(expectedError, fn) { + try { + fn(); + fail('Expected error but none thrown'); + } catch (e) { + // throw again the exception thorwned by 'fail' above + if (e instanceof JsUnitException) throw e; + + // throwned class and message should be as expected + assertEquals(expectedError.name, e.name); + assertEquals(expectedError.message, e.message) + } +} + function testSchemaXSDString() { var t = Jsonix.Schema.XSD.String.INSTANCE; assertEquals('test', t.print('test')); @@ -191,6 +205,48 @@ function testSchemaXSDCalendar() { } +function testSchemaXSDCalendarError() { + expectError( + new Error('Value [nomatch] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch') }); + + expectError( + new Error('Value [201002] does not match the xs:gYearMonth pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); }); + + expectError( + new Error('Value [10] does not match the xs:gYear pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); }); + + expectError( + new Error('Value [02-10] does not match the xs:gMonthDay pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); }); + + expectError( + new Error('Value [02] does not match the xs:gMonth pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); }); + + expectError( + new Error('Value [01] does not match the xs:gDay pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); }); + + expectError( + new Error('Value [2010-02-01 12:23:0] does not match the xs:date pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); }); + + expectError( + new Error('Value [20100201] does not match the xs:date pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201') }); + + expectError( + new Error('Value [12:23:0] does not match the xs:time pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); }); + + expectError( + new Error('Value [PDT] does not match the timezone pattern.'), + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); }); +} + function testSchemaXSDTime() { var t0 = Jsonix.Schema.XSD.TimeAsDate.INSTANCE.parse('10:00:00.5'); var time0 = new Date(1970, 0, 1, 10, 0, 0); From 9461ab0c06f152e30e09cd035238a780b6d36009 Mon Sep 17 00:00:00 2001 From: Alexey Valikov Date: Sun, 17 Feb 2019 18:05:10 +0100 Subject: [PATCH 3/4] Moved tests to nodeunit. #210 --- nodejs/scripts/tests/xsd.js | 40 +++++++++++++ .../hisrc/jsonix/test/JsonixSchemaXSDTest.js | 56 ------------------- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/nodejs/scripts/tests/xsd.js b/nodejs/scripts/tests/xsd.js index 0263651f8..812d4c173 100644 --- a/nodejs/scripts/tests/xsd.js +++ b/nodejs/scripts/tests/xsd.js @@ -222,6 +222,46 @@ module.exports = test.equal(-733, gd.timezone); test.equal('---06-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gd)); + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch'); }, + /Value \[nomatch\] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); }, + /Value \[201002\] does not match the xs:gYearMonth pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); }, + /Value \[10\] does not match the xs:gYear pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); }, + /Value \[02-10\] does not match the xs:gMonthDay pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); }, + /Value \[02\] does not match the xs:gMonth pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); }, + /Value \[01\] does not match the xs:gDay pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); }, + /Value \[2010-02-01 12:23:0\] does not match the xs:date pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201'); }, + /Value \[20100201\] does not match the xs:date pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); }, + /Value \[12:23:0\] does not match the xs:time pattern\./); + + test.throws( + function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); }, + /Value \[PDT\] does not match the timezone pattern\./); + test.done(); }, diff --git a/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js b/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js index aeea37027..ac9328248 100644 --- a/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js +++ b/scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js @@ -1,17 +1,3 @@ -function expectError(expectedError, fn) { - try { - fn(); - fail('Expected error but none thrown'); - } catch (e) { - // throw again the exception thorwned by 'fail' above - if (e instanceof JsUnitException) throw e; - - // throwned class and message should be as expected - assertEquals(expectedError.name, e.name); - assertEquals(expectedError.message, e.message) - } -} - function testSchemaXSDString() { var t = Jsonix.Schema.XSD.String.INSTANCE; assertEquals('test', t.print('test')); @@ -205,48 +191,6 @@ function testSchemaXSDCalendar() { } -function testSchemaXSDCalendarError() { - expectError( - new Error('Value [nomatch] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch') }); - - expectError( - new Error('Value [201002] does not match the xs:gYearMonth pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); }); - - expectError( - new Error('Value [10] does not match the xs:gYear pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); }); - - expectError( - new Error('Value [02-10] does not match the xs:gMonthDay pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); }); - - expectError( - new Error('Value [02] does not match the xs:gMonth pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); }); - - expectError( - new Error('Value [01] does not match the xs:gDay pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); }); - - expectError( - new Error('Value [2010-02-01 12:23:0] does not match the xs:date pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); }); - - expectError( - new Error('Value [20100201] does not match the xs:date pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201') }); - - expectError( - new Error('Value [12:23:0] does not match the xs:time pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); }); - - expectError( - new Error('Value [PDT] does not match the timezone pattern.'), - function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); }); -} - function testSchemaXSDTime() { var t0 = Jsonix.Schema.XSD.TimeAsDate.INSTANCE.parse('10:00:00.5'); var time0 = new Date(1970, 0, 1, 10, 0, 0); From c3f2364151714b17c7c4ca0e63551fffc12f29ec Mon Sep 17 00:00:00 2001 From: Alexey Valikov Date: Sun, 17 Feb 2019 18:10:51 +0100 Subject: [PATCH 4/4] Updated Jsonix scripts. Fixes #210. --- dist/Jsonix-all.js | 9 +++++---- dist/Jsonix-min.js | 19 ++++++++++--------- nodejs/scripts/jsonix.js | 9 +++++---- nodejs/tests/ar/package-lock.json | 2 +- nodejs/tests/basic/package-lock.json | 2 +- nodejs/tests/browserify/package-lock.json | 2 +- nodejs/tests/po/package-lock.json | 2 +- nodejs/tests/wps/package-lock.json | 2 +- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/dist/Jsonix-all.js b/dist/Jsonix-all.js index d4d4e2d96..3e64d0aa5 100644 --- a/dist/Jsonix-all.js +++ b/dist/Jsonix-all.js @@ -921,6 +921,7 @@ Jsonix.XML.QName.key = function(namespaceURI, localPart) { Jsonix.Util.Ensure.ensureString(localPart); if (namespaceURI) { var colonPosition = localPart.indexOf(':'); + var localName; if (colonPosition > 0 && colonPosition < localPart.length) { localName = localPart.substring(colonPosition + 1); } else { @@ -4901,7 +4902,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseDate : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -4916,7 +4917,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseTime : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -4932,7 +4933,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:time pattern.'); + throw new Error('Value [' + text + '] does not match the xs:time pattern.'); }, parseTimezoneString : function(text) { // (('+' | '-') hh ':' mm) | 'Z' @@ -4955,7 +4956,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { var minute = parseInt(results[5], 10); return sign * (hour * 60 + minute); } - throw new Error('Value [' + value + '] does not match the timezone pattern.'); + throw new Error('Value [' + text + '] does not match the timezone pattern.'); } }, print : function(value, context, output, scope) { diff --git a/dist/Jsonix-min.js b/dist/Jsonix-min.js index a809535d9..7ed3f78c7 100644 --- a/dist/Jsonix-min.js +++ b/dist/Jsonix-min.js @@ -331,11 +331,12 @@ return new Jsonix.XML.QName(e,f,g) Jsonix.XML.QName.fromObjectOrString=function(f,d,e){if(Jsonix.Util.Type.isString(f)){return Jsonix.XML.QName.fromString(f,d,e) }else{return Jsonix.XML.QName.fromObject(f) }}; -Jsonix.XML.QName.key=function(f,e){Jsonix.Util.Ensure.ensureString(e); -if(f){var d=e.indexOf(":"); -if(d>0&&d0&&h 0 && colonPosition < localPart.length) { localName = localPart.substring(colonPosition + 1); } else { @@ -4901,7 +4902,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseDate : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -4916,7 +4917,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:date pattern.'); + throw new Error('Value [' + text + '] does not match the xs:date pattern.'); }, parseTime : function(text, context, input, scope) { Jsonix.Util.Ensure.ensureString(text); @@ -4932,7 +4933,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { }; return new Jsonix.XML.Calendar(data); } - throw new Error('Value [' + value + '] does not match the xs:time pattern.'); + throw new Error('Value [' + text + '] does not match the xs:time pattern.'); }, parseTimezoneString : function(text) { // (('+' | '-') hh ':' mm) | 'Z' @@ -4955,7 +4956,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, { var minute = parseInt(results[5], 10); return sign * (hour * 60 + minute); } - throw new Error('Value [' + value + '] does not match the timezone pattern.'); + throw new Error('Value [' + text + '] does not match the timezone pattern.'); } }, print : function(value, context, output, scope) { diff --git a/nodejs/tests/ar/package-lock.json b/nodejs/tests/ar/package-lock.json index e9a951229..79da81e06 100644 --- a/nodejs/tests/ar/package-lock.json +++ b/nodejs/tests/ar/package-lock.json @@ -670,7 +670,7 @@ }, "jsonix": { "version": "file:../../scripts/jsonix-2.4.2-SNAPSHOT.tgz", - "integrity": "sha512-IwkkaE3n7MjlA7LI1HEjGYSQxJoqP+WYk7Uaagkoq9wxbbTSJj43P1qlMR0YxPHXaIYyD7ktUbriqIkfKBpj5w==", + "integrity": "sha512-zhmtN7E2h9bQ8UOUnraOgiOVSuqbG0N39JZaRXe7xcksfijzjyEitjdsSmydRlLLSGjCobH5jBD4+qU7J9kWaw==", "requires": { "amdefine": "0.x.x", "xmldom": ">=0.1.21", diff --git a/nodejs/tests/basic/package-lock.json b/nodejs/tests/basic/package-lock.json index 1ef1e2038..8ae5f686e 100644 --- a/nodejs/tests/basic/package-lock.json +++ b/nodejs/tests/basic/package-lock.json @@ -683,7 +683,7 @@ }, "jsonix": { "version": "file:../../scripts/jsonix-2.4.2-SNAPSHOT.tgz", - "integrity": "sha512-IwkkaE3n7MjlA7LI1HEjGYSQxJoqP+WYk7Uaagkoq9wxbbTSJj43P1qlMR0YxPHXaIYyD7ktUbriqIkfKBpj5w==", + "integrity": "sha512-zhmtN7E2h9bQ8UOUnraOgiOVSuqbG0N39JZaRXe7xcksfijzjyEitjdsSmydRlLLSGjCobH5jBD4+qU7J9kWaw==", "requires": { "amdefine": "0.x.x", "xmldom": ">=0.1.21", diff --git a/nodejs/tests/browserify/package-lock.json b/nodejs/tests/browserify/package-lock.json index 93d1c15ab..2eea0d67c 100644 --- a/nodejs/tests/browserify/package-lock.json +++ b/nodejs/tests/browserify/package-lock.json @@ -669,7 +669,7 @@ }, "jsonix": { "version": "file:../../scripts/jsonix-2.4.2-SNAPSHOT.tgz", - "integrity": "sha512-IwkkaE3n7MjlA7LI1HEjGYSQxJoqP+WYk7Uaagkoq9wxbbTSJj43P1qlMR0YxPHXaIYyD7ktUbriqIkfKBpj5w==", + "integrity": "sha512-zhmtN7E2h9bQ8UOUnraOgiOVSuqbG0N39JZaRXe7xcksfijzjyEitjdsSmydRlLLSGjCobH5jBD4+qU7J9kWaw==", "requires": { "amdefine": "0.x.x", "xmldom": ">=0.1.21", diff --git a/nodejs/tests/po/package-lock.json b/nodejs/tests/po/package-lock.json index 6baa3a86c..fafea5d4b 100644 --- a/nodejs/tests/po/package-lock.json +++ b/nodejs/tests/po/package-lock.json @@ -665,7 +665,7 @@ }, "jsonix": { "version": "file:../../scripts/jsonix-2.4.2-SNAPSHOT.tgz", - "integrity": "sha512-IwkkaE3n7MjlA7LI1HEjGYSQxJoqP+WYk7Uaagkoq9wxbbTSJj43P1qlMR0YxPHXaIYyD7ktUbriqIkfKBpj5w==", + "integrity": "sha512-zhmtN7E2h9bQ8UOUnraOgiOVSuqbG0N39JZaRXe7xcksfijzjyEitjdsSmydRlLLSGjCobH5jBD4+qU7J9kWaw==", "requires": { "amdefine": "0.x.x", "xmldom": ">=0.1.21", diff --git a/nodejs/tests/wps/package-lock.json b/nodejs/tests/wps/package-lock.json index 682ab320a..ce606a37c 100644 --- a/nodejs/tests/wps/package-lock.json +++ b/nodejs/tests/wps/package-lock.json @@ -678,7 +678,7 @@ }, "jsonix": { "version": "file:../../scripts/jsonix-2.4.2-SNAPSHOT.tgz", - "integrity": "sha512-IwkkaE3n7MjlA7LI1HEjGYSQxJoqP+WYk7Uaagkoq9wxbbTSJj43P1qlMR0YxPHXaIYyD7ktUbriqIkfKBpj5w==", + "integrity": "sha512-zhmtN7E2h9bQ8UOUnraOgiOVSuqbG0N39JZaRXe7xcksfijzjyEitjdsSmydRlLLSGjCobH5jBD4+qU7J9kWaw==", "requires": { "amdefine": "0.x.x", "xmldom": ">=0.1.21",