]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Backport (#30383)
authorJohann-S <johann.servoire@gmail.com>
Fri, 20 Mar 2020 21:33:23 +0000 (22:33 +0100)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 31 Mar 2020 18:11:29 +0000 (21:11 +0300)
fix: ensure totype always return stringified null when null passed

js/src/util.js
js/tests/unit/util.js

index d130682e351de9cb88d88d658a568c26197a5b1a..95186bb6626a2191de27ada668ed94892c54cf79 100644 (file)
@@ -19,6 +19,10 @@ const MILLISECONDS_MULTIPLIER = 1000
 
 // Shoutout AngusCroll (https://goo.gl/pxwQGp)
 function toType(obj) {
+  if (obj === null || typeof obj === 'undefined') {
+    return `${obj}`
+  }
+
   return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
 }
 
index e7e22cea97cbd83ac29c27d6a49b6bb31388b323..18a05b269f3f711a232626a5bf1e050136a219db 100644 (file)
@@ -51,6 +51,26 @@ $(function () {
     }
   })
 
+  QUnit.test('Util.typeCheckConfig should return null/undefined stringified when passed', function (assert) {
+    assert.expect(1)
+    var namePlugin = 'collapse'
+    var defaultType = {
+      toggle: '(null|undefined)'
+    }
+    var config = {
+      toggle: null
+    }
+
+    Util.typeCheckConfig(namePlugin, config, defaultType)
+
+    // eslint-disable-next-line
+    config.toggle = undefined
+
+    Util.typeCheckConfig(namePlugin, config, defaultType)
+
+    assert.strictEqual(true, true)
+  })
+
   QUnit.test('Util.isElement should check if we passed an element or not', function (assert) {
     assert.expect(3)
     var $div = $('<div id="test"></div>').appendTo($('#qunit-fixture'))