Repository: jsonata-js/jsonata (js)

Issue:
$parseInteger fails with "#" picture string
I'm doing this from Node Red, which is using JSONata 1.6, so this may have been fixed, but I cannot confirm.

`$parseInteger("50", "#")` produces the following error:

`Invalid JSONata expression: matchSpec.parse is not a function`.

After some investigation I found `$formatInteger(50, "#")` is not handled, but produces a better error message:

`Invalid JSONata expression: Formatting an integer as a sequence starting with "#" is not supported by this implementation`

This looks like error D3130, and since this error still exists in 1.7, I'm guessing the other error still occurs too. Is it possible to improve the error message?


Pull request:
check for unsupported sequence in parseInteger
`$parseInteger` is missing a check that is in `$formatInteger`

resolves #387 

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>

Patch:
diff --git a/src/datetime.js b/src/datetime.js
index f611aba..a0d8535 100644
--- a/src/datetime.js
+++ b/src/datetime.js
@@ -1030,6 +1030,12 @@ const dateTime = (function () {
                         }
                         return parseInt(digits);
                     };
+                    break;
+                case formats.SEQUENCE:
+                    throw {
+                        code: 'D3130',
+                        value: formatSpec.token
+                    };
             }
 
         }
diff --git a/src/jsonata.js b/src/jsonata.js
index b43355b..7cebe55 100644
--- a/src/jsonata.js
+++ b/src/jsonata.js
@@ -1970,7 +1970,7 @@ var jsonata = (function() {
         "D3110": "The argument of the toMillis function must be an ISO 8601 formatted timestamp. Given {{value}}",
         "D3120": "Syntax error in expression passed to function eval: {{value}}",
         "D3121": "Dynamic error evaluating the expression passed to function eval: {{value}}",
-        "D3130": "Formatting an integer as a sequence starting with {{value}} is not supported by this implementation",
+        "D3130": "Formatting or parsing an integer as a sequence starting with {{value}} is not supported by this implementation",
         "D3131": "In a decimal digit pattern, all digits must be from the same decimal group",
         "D3132": "Unknown component specifier {{value}} in date/time picture string",
         "D3133": "The 'name' modifier can only be applied to months and days in the date/time picture string, not {{value}}",


Test patch:
diff --git a/test/test-suite/groups/function-parseInteger/parseInteger.json b/test/test-suite/groups/function-parseInteger/parseInteger.json
index 09eb121..5729f75 100644
--- a/test/test-suite/groups/function-parseInteger/parseInteger.json
+++ b/test/test-suite/groups/function-parseInteger/parseInteger.json
@@ -478,5 +478,13 @@
         "expr": "$parseInteger('FZPH', 'A')",
         "data": {},
         "result": 123456
+    },
+    {
+        "function": "#parseInteger",
+        "category": "errors",
+        "description": "unsupported picture string",
+        "expr": "$parseInteger('50', '#')",
+        "data": {},
+        "code": "D3130"
     }
 ]