From f12f78a90ee630cf01d9ce7c11a31e3e28166ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 12 Sep 2016 13:58:40 +0200 Subject: [PATCH] Add rest-coercion tests for zero-prefixed numbers --- test/rest-coercion/urlencoded-any.suite.js | 5 +++++ test/rest-coercion/urlencoded-array.suite.js | 18 ++++++++++++++++++ test/rest-coercion/urlencoded-integer.suite.js | 6 ++++++ test/rest-coercion/urlencoded-number.suite.js | 6 ++++++ test/rest-coercion/urlencoded-string.suite.js | 5 +++++ 5 files changed, 40 insertions(+) diff --git a/test/rest-coercion/urlencoded-any.suite.js b/test/rest-coercion/urlencoded-any.suite.js index 1657fd32..ffddfd88 100644 --- a/test/rest-coercion/urlencoded-any.suite.js +++ b/test/rest-coercion/urlencoded-any.suite.js @@ -62,6 +62,11 @@ function suite(prefix, ctx) { // Numbers larger than MAX_SAFE_INTEGER are treated as strings ['arg=2343546576878989879789', '2343546576878989879789'], ['arg=-2343546576878989879789', '-2343546576878989879789'], + // Numbers starting with a leading zero are treated as strings + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', '0668'], + // However, floats are correctly parsed + ['arg=0.42', 0.42], // Scientific notation should be recognized as a number ['arg=1.234e%2B30', '1.234e+30'], ['arg=-1.234e%2B30', '-1.234e+30'], diff --git a/test/rest-coercion/urlencoded-array.suite.js b/test/rest-coercion/urlencoded-array.suite.js index f760cfd5..8cf2828d 100644 --- a/test/rest-coercion/urlencoded-array.suite.js +++ b/test/rest-coercion/urlencoded-array.suite.js @@ -127,6 +127,12 @@ function suite(prefix, ctx) { ['arg={}', ERROR_BAD_REQUEST], ['arg={"a":true}', ERROR_BAD_REQUEST], + // Numbers starting with a leading zero are parsed, + // because we know the expected type is a number. + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', [668]], + ['arg=0.42', [0.42]], + // Malformed JSON should trigger ERROR_BAD_REQUEST ['arg={malformed}', ERROR_BAD_REQUEST], ['arg=[malformed]', ERROR_BAD_REQUEST], @@ -163,6 +169,12 @@ function suite(prefix, ctx) { ['arg={}', ['{}']], ['arg={"a":true}', ['{"a":true}']], ['arg={malformed}', ['{malformed}']], + + // Numbers starting with a leading zero are treated as strings + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', ['0668']], + ['arg=0.42', ['0.42']], + // Invalid values should trigger ERROR_BAD_REQUEST ['arg=[1]', ERROR_BAD_REQUEST], ['arg=[1,2]', ERROR_BAD_REQUEST], @@ -249,6 +261,12 @@ function suite(prefix, ctx) { // Scientific notation - should it be recognized as a number? ['arg=1.234e%2B30&arg=-1.234e%2B30', ['1.234e+30', '-1.234e+30']], + // Integers starting with a leading zero are treated as strings + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', ['0668']], + // However, floats are correctly parsed + ['arg=0.42', [0.42]], + // Valid values - JSON encoding ['arg=[]', []], ['arg=["text",10,false]', ['text', 10, false]], diff --git a/test/rest-coercion/urlencoded-integer.suite.js b/test/rest-coercion/urlencoded-integer.suite.js index 5bf58d21..98243612 100644 --- a/test/rest-coercion/urlencoded-integer.suite.js +++ b/test/rest-coercion/urlencoded-integer.suite.js @@ -68,6 +68,12 @@ function suite(prefix, ctx) { ['arg=[1,2]', ERROR_BAD_REQUEST], ['arg={}', ERROR_BAD_REQUEST], ['arg={"a":true}', ERROR_BAD_REQUEST], + + // Numbers starting with a leading zero are parsed, + // because we know the expected type is a number. + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', 668], + ['arg=0.42', ERROR_BAD_REQUEST], // not an integer ]); }); } diff --git a/test/rest-coercion/urlencoded-number.suite.js b/test/rest-coercion/urlencoded-number.suite.js index 31e59096..2d0fb863 100644 --- a/test/rest-coercion/urlencoded-number.suite.js +++ b/test/rest-coercion/urlencoded-number.suite.js @@ -67,6 +67,12 @@ function suite(prefix, ctx) { ['arg=[1,2]', ERROR_BAD_REQUEST], ['arg={}', ERROR_BAD_REQUEST], ['arg={"a":true}', ERROR_BAD_REQUEST], + + // Numbers starting with a leading zero are parsed, + // because we know the expected type is a number. + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', 668], + ['arg=0.42', 0.42], ]); }); } diff --git a/test/rest-coercion/urlencoded-string.suite.js b/test/rest-coercion/urlencoded-string.suite.js index 73e6f5bd..a13f1467 100644 --- a/test/rest-coercion/urlencoded-string.suite.js +++ b/test/rest-coercion/urlencoded-string.suite.js @@ -62,6 +62,11 @@ function suite(prefix, ctx) { // Scientific notation ['arg=1.234e%2B30', '1.234e+30'], ['arg=-1.234e%2B30', '-1.234e+30'], + + // Numbers starting with a leading zero are treated as strings + // See https://github.com/strongloop/strong-remoting/issues/143 + ['arg=0668', '0668'], + ['arg=0.42', '0.42'], ]); }); }