From 3805f96cabe5acb4e4b50242d718abc5a4b988a6 Mon Sep 17 00:00:00 2001 From: Eli Siegel Date: Mon, 7 Mar 2022 17:15:10 +0200 Subject: [PATCH] fixed failure when params have an object with key = toString (#3) * fixed failure when params have an object with key = toString --- lib/parameters.js | 8 +++++++- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/parameters.js b/lib/parameters.js index a0d8292..8a3d080 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -62,7 +62,13 @@ Object.assign(Parameters, { _isPrimitive: function (value) { return PRIMITIVE_TYPES.some(function (Primitive) { - return [typeof value, String(value)].some(function (val) { return val === Primitive.name.toLowerCase() }) + let initValue; + try { + initValue = String(value) + } catch (error) { + initValue = ''; + } + return [typeof value, initValue].some(function (val) { return val === Primitive.name.toLowerCase() }) }) }, diff --git a/package-lock.json b/package-lock.json index 5f140fb..31c3b38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "strong-params", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d864246..6aaaf3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strong-params", - "version": "1.0.3", + "version": "1.0.4", "description": "Rails-style strong parameters for javascript projects. (e.g. Express, Koa)", "main": "index.js", "scripts": {