Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohann-S <johann.servoire@gmail.com>2020-03-18 14:10:55 +0300
committerGitHub <noreply@github.com>2020-03-18 14:10:55 +0300
commitaff115219ee47b261b943bbe65cf5919fe021a22 (patch)
treecff50377c0c3fdaabf09fcdc7ee49327c2f6eaf2 /js
parentd773cafe3dacee19639ec7b523fb9b4c89ec0129 (diff)
fix: ensure `totype` always returns stringified null/undefined when null/undefined is passed (#30383)
Diffstat (limited to 'js')
-rw-r--r--js/src/util/index.js8
-rw-r--r--js/tests/unit/util/index.spec.js31
2 files changed, 37 insertions, 2 deletions
diff --git a/js/src/util/index.js b/js/src/util/index.js
index 8a5ae21566..fca2a91977 100644
--- a/js/src/util/index.js
+++ b/js/src/util/index.js
@@ -10,7 +10,13 @@ const MILLISECONDS_MULTIPLIER = 1000
const TRANSITION_END = 'transitionend'
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
-const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase())
+const toType = obj => {
+ if (obj === null || obj === undefined) {
+ return `${obj}`
+ }
+
+ return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
+}
/**
* --------------------------------------------------------------------------
diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js
index 42c273f060..57ca1a9c73 100644
--- a/js/tests/unit/util/index.spec.js
+++ b/js/tests/unit/util/index.spec.js
@@ -198,8 +198,9 @@ describe('Util', () => {
})
describe('typeCheckConfig', () => {
+ const namePlugin = 'collapse'
+
it('should check type of the config object', () => {
- const namePlugin = 'collapse'
const defaultType = {
toggle: 'boolean',
parent: '(string|element)'
@@ -213,6 +214,34 @@ describe('Util', () => {
Util.typeCheckConfig(namePlugin, config, defaultType)
}).toThrow(new Error('COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".'))
})
+
+ it('should return null stringified when null is passed', () => {
+ const defaultType = {
+ toggle: 'boolean',
+ parent: '(null|element)'
+ }
+ const config = {
+ toggle: true,
+ parent: null
+ }
+
+ Util.typeCheckConfig(namePlugin, config, defaultType)
+ expect().nothing()
+ })
+
+ it('should return undefined stringified when undefined is passed', () => {
+ const defaultType = {
+ toggle: 'boolean',
+ parent: '(undefined|element)'
+ }
+ const config = {
+ toggle: true,
+ parent: undefined
+ }
+
+ Util.typeCheckConfig(namePlugin, config, defaultType)
+ expect().nothing()
+ })
})
describe('makeArray', () => {