From 48c079a9b8396a32b9fb9e371568e8fccedfdec4 Mon Sep 17 00:00:00 2001 From: Tieson Trowbridge Date: Sun, 3 Nov 2019 22:33:44 -0500 Subject: [PATCH] Fixes incorrect value validation for step attribute --- README.md | 4 ++-- bootbox.all.js | 15 ++++---------- bootbox.js | 6 ++++-- bootbox.locales.js | 2 +- dist/bootbox.all.min.js | 4 ++-- dist/bootbox.locales.min.js | 2 +- dist/bootbox.min.js | 4 ++-- header.txt | 2 +- package.json | 2 +- tests/prompt.test.js | 41 ++++++++++++++++++++++++++++++++++--- 10 files changed, 56 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 24aa261e..9add8e63 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ Bootbox **3.3.0** is the *last* release to support Bootstrap 2.2.x. Much more dependency information can be found [on the Bootbox website](http://bootboxjs.com/getting-started.html#bootbox-dependencies). -## 5.3.2 (Latest Release) +## 5.3.3 (Latest Release) -- Adds Georgian (ka) locale. +- Fixes incorrect value validation for the `step` option when setting `inputType` to `number` for a prompt. For a full list of releases and changes please see [the changelog](https://github.com/makeusabrew/bootbox/blob/master/CHANGELOG.md). diff --git a/bootbox.all.js b/bootbox.all.js index 021794a3..f37466aa 100644 --- a/bootbox.all.js +++ b/bootbox.all.js @@ -1,6 +1,6 @@ /*! @preserve * bootbox.js - * version: 5.3.2 + * version: 5.3.3 * author: Nick Payne * license: MIT * http://bootboxjs.com/ @@ -880,7 +880,7 @@ // @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Setting_maximum_and_minimum_dates if (options.inputType !== 'date') { if (options.step) { - if (options.step === 'any' || (!isNaN(options.step) && parseInt(options.step) > 0)) { + if (options.step === 'any' || (!isNaN(options.step) && parseFloat(options.step) > 0)) { input.attr('step', options.step); } else { @@ -1346,10 +1346,12 @@ } else { if (min !== undefined && isNaN(min)) { + minValid = false; throw new Error('"min" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min for more information.'); } if (max !== undefined && isNaN(max)) { + maxValid = false; throw new Error('"max" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.'); } } @@ -1374,15 +1376,6 @@ return /(\d{4})-(\d{2})-(\d{2})/.test(value); } - - // Register the default locale - exports.addLocale('en', { - OK: 'OK', - CANCEL: 'Cancel', - CONFIRM: 'OK' - }); - - // The Bootbox object return exports; })); \ No newline at end of file diff --git a/bootbox.js b/bootbox.js index 0975b56b..4d9ec213 100644 --- a/bootbox.js +++ b/bootbox.js @@ -1,6 +1,6 @@ /*! @preserve * bootbox.js - * version: 5.3.2 + * version: 5.3.3 * author: Nick Payne * license: MIT * http://bootboxjs.com/ @@ -679,7 +679,7 @@ // @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Setting_maximum_and_minimum_dates if (options.inputType !== 'date') { if (options.step) { - if (options.step === 'any' || (!isNaN(options.step) && parseInt(options.step) > 0)) { + if (options.step === 'any' || (!isNaN(options.step) && parseFloat(options.step) > 0)) { input.attr('step', options.step); } else { @@ -1145,10 +1145,12 @@ } else { if (min !== undefined && isNaN(min)) { + minValid = false; throw new Error('"min" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min for more information.'); } if (max !== undefined && isNaN(max)) { + maxValid = false; throw new Error('"max" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.'); } } diff --git a/bootbox.locales.js b/bootbox.locales.js index b30e4f2b..015c205e 100644 --- a/bootbox.locales.js +++ b/bootbox.locales.js @@ -1,6 +1,6 @@ /*! @preserve * bootbox.locales.js - * version: 5.3.2 + * version: 5.3.3 * author: Nick Payne * license: MIT * http://bootboxjs.com/ diff --git a/dist/bootbox.all.min.js b/dist/bootbox.all.min.js index 93482b83..6f052c77 100644 --- a/dist/bootbox.all.min.js +++ b/dist/bootbox.all.min.js @@ -1,6 +1,6 @@ /** - * bootbox.js 5.3.2 + * bootbox.js 5.3.3 * * http://bootboxjs.com/license.txt */ -!function(t,e){'use strict';'function'==typeof define&&define.amd?define(['jquery'],e):'object'==typeof exports?module.exports=e(require('jquery')):t.bootbox=e(t.jQuery)}(this,function e(p,u){'use strict';var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable('toString'),l=(i=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor']).length,function(t){if('function'!=typeof t&&('object'!=typeof t||null===t))throw new TypeError('Object.keys called on non-object');var e,o,a=[];for(e in t)r.call(t,e)&&a.push(e);if(n)for(o=0;o
",header:"
",footer:'',closeButton:'',form:'
',button:'',option:'',promptMessage:'
',inputs:{text:'',textarea:'',email:'',select:'',checkbox:'
',radio:'
',date:'',time:'',number:'',password:'',range:''}},m={locale:'en',backdrop:'static',animate:!0,className:null,closeButton:!0,show:!0,container:'body',value:'',inputType:'text',swapButtonOrder:!1,centerVertical:!1,multiple:!1,scrollable:!1};function c(t,e,o){return p.extend(!0,{},t,function(t,e){var o=t.length,a={};if(o<1||2').attr('label',e.group)),o=i[e.group]);var a=p(f.option);a.attr('value',e.value).text(e.text),o.append(a)}),O(i,function(t,e){n.append(e)}),n.val(r.value);break;case'checkbox':var l=p.isArray(r.value)?r.value:[r.value];if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "checkbox" requires at least one option');n=p('
'),O(a,function(t,o){if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');var a=p(f.inputs[r.inputType]);a.find('input').attr('value',o.value),a.find('label').append('\n'+o.text),O(l,function(t,e){e===o.value&&a.find('input').prop('checked',!0)}),n.append(a)});break;case'radio':if(r.value!==u&&p.isArray(r.value))throw new Error('prompt with "inputType" set to "radio" requires a single, non-array value for "value"');if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "radio" requires at least one option');n=p('
');var s=!0;O(a,function(t,e){if(e.value===u||e.text===u)throw new Error('each option needs a "value" property and a "text" property');var o=p(f.inputs[r.inputType]);o.find('input').attr('value',e.value),o.find('label').append('\n'+e.text),r.value!==u&&e.value===r.value&&(o.find('input').prop('checked',!0),s=!1),n.append(o)}),s&&n.find('input[type="radio"]').first().prop('checked',!0)}if(t.append(n),t.on('submit',function(t){t.preventDefault(),t.stopPropagation(),e.find('.bootbox-accept').trigger('click')}),''!==p.trim(r.message)){var c=p(f.promptMessage).html(r.message);t.prepend(c),r.message=t}else r.message=t;return(e=d.dialog(r)).off('shown.bs.modal'),e.on('shown.bs.modal',function(){n.focus()}),!0===o&&e.modal('show'),e},d.addLocale('en',{OK:'OK',CANCEL:'Cancel',CONFIRM:'OK'}),d}); \ No newline at end of file +!function(t,e){'use strict';'function'==typeof define&&define.amd?define(['jquery'],e):'object'==typeof exports?module.exports=e(require('jquery')):t.bootbox=e(t.jQuery)}(this,function e(p,u){'use strict';var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable('toString'),l=(i=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor']).length,function(t){if('function'!=typeof t&&('object'!=typeof t||null===t))throw new TypeError('Object.keys called on non-object');var e,o,a=[];for(e in t)r.call(t,e)&&a.push(e);if(n)for(o=0;o
",header:"
",footer:'',closeButton:'',form:'
',button:'',option:'',promptMessage:'
',inputs:{text:'',textarea:'',email:'',select:'',checkbox:'
',radio:'
',date:'',time:'',number:'',password:'',range:''}},m={locale:'en',backdrop:'static',animate:!0,className:null,closeButton:!0,show:!0,container:'body',value:'',inputType:'text',swapButtonOrder:!1,centerVertical:!1,multiple:!1,scrollable:!1};function c(t,e,o){return p.extend(!0,{},t,function(t,e){var o=t.length,a={};if(o<1||2').attr('label',e.group)),o=i[e.group]);var a=p(f.option);a.attr('value',e.value).text(e.text),o.append(a)}),O(i,function(t,e){n.append(e)}),n.val(r.value);break;case'checkbox':var l=p.isArray(r.value)?r.value:[r.value];if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "checkbox" requires at least one option');n=p('
'),O(a,function(t,o){if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');var a=p(f.inputs[r.inputType]);a.find('input').attr('value',o.value),a.find('label').append('\n'+o.text),O(l,function(t,e){e===o.value&&a.find('input').prop('checked',!0)}),n.append(a)});break;case'radio':if(r.value!==u&&p.isArray(r.value))throw new Error('prompt with "inputType" set to "radio" requires a single, non-array value for "value"');if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "radio" requires at least one option');n=p('
');var s=!0;O(a,function(t,e){if(e.value===u||e.text===u)throw new Error('each option needs a "value" property and a "text" property');var o=p(f.inputs[r.inputType]);o.find('input').attr('value',e.value),o.find('label').append('\n'+e.text),r.value!==u&&e.value===r.value&&(o.find('input').prop('checked',!0),s=!1),n.append(o)}),s&&n.find('input[type="radio"]').first().prop('checked',!0)}if(t.append(n),t.on('submit',function(t){t.preventDefault(),t.stopPropagation(),e.find('.bootbox-accept').trigger('click')}),''!==p.trim(r.message)){var c=p(f.promptMessage).html(r.message);t.prepend(c),r.message=t}else r.message=t;return(e=d.dialog(r)).off('shown.bs.modal'),e.on('shown.bs.modal',function(){n.focus()}),!0===o&&e.modal('show'),e},d}); \ No newline at end of file diff --git a/dist/bootbox.locales.min.js b/dist/bootbox.locales.min.js index 27ecb137..fc1f1474 100644 --- a/dist/bootbox.locales.min.js +++ b/dist/bootbox.locales.min.js @@ -1,5 +1,5 @@ /** - * bootbox.js 5.3.2 + * bootbox.js 5.3.3 * * http://bootboxjs.com/license.txt */ diff --git a/dist/bootbox.min.js b/dist/bootbox.min.js index d140a4da..9dc595a9 100644 --- a/dist/bootbox.min.js +++ b/dist/bootbox.min.js @@ -1,6 +1,6 @@ /** - * bootbox.js 5.3.2 + * bootbox.js 5.3.3 * * http://bootboxjs.com/license.txt */ -!function(e,t){'use strict';'function'==typeof define&&define.amd?define(['jquery'],t):'object'==typeof exports?module.exports=t(require('jquery')):e.bootbox=t(e.jQuery)}(this,function t(p,u){'use strict';var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable('toString'),l=(i=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor']).length,function(e){if('function'!=typeof e&&('object'!=typeof e||null===e))throw new TypeError('Object.keys called on non-object');var t,o,a=[];for(t in e)r.call(e,t)&&a.push(t);if(n)for(o=0;o
",header:"
",footer:'',closeButton:'',form:'
',button:'',option:'',promptMessage:'
',inputs:{text:'',textarea:'',email:'',select:'',checkbox:'
',radio:'
',date:'',time:'',number:'',password:'',range:''}},m={locale:'en',backdrop:'static',animate:!0,className:null,closeButton:!0,show:!0,container:'body',value:'',inputType:'text',swapButtonOrder:!1,centerVertical:!1,multiple:!1,scrollable:!1};function c(e,t,o){return p.extend(!0,{},e,function(e,t){var o=e.length,a={};if(o<1||2').attr('label',t.group)),o=i[t.group]);var a=p(f.option);a.attr('value',t.value).text(t.text),o.append(a)}),v(i,function(e,t){n.append(t)}),n.val(r.value);break;case'checkbox':var l=p.isArray(r.value)?r.value:[r.value];if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "checkbox" requires at least one option');n=p('
'),v(a,function(e,o){if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');var a=p(f.inputs[r.inputType]);a.find('input').attr('value',o.value),a.find('label').append('\n'+o.text),v(l,function(e,t){t===o.value&&a.find('input').prop('checked',!0)}),n.append(a)});break;case'radio':if(r.value!==u&&p.isArray(r.value))throw new Error('prompt with "inputType" set to "radio" requires a single, non-array value for "value"');if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "radio" requires at least one option');n=p('
');var s=!0;v(a,function(e,t){if(t.value===u||t.text===u)throw new Error('each option needs a "value" property and a "text" property');var o=p(f.inputs[r.inputType]);o.find('input').attr('value',t.value),o.find('label').append('\n'+t.text),r.value!==u&&t.value===r.value&&(o.find('input').prop('checked',!0),s=!1),n.append(o)}),s&&n.find('input[type="radio"]').first().prop('checked',!0)}if(e.append(n),e.on('submit',function(e){e.preventDefault(),e.stopPropagation(),t.find('.bootbox-accept').trigger('click')}),''!==p.trim(r.message)){var c=p(f.promptMessage).html(r.message);e.prepend(c),r.message=e}else r.message=e;return(t=d.dialog(r)).off('shown.bs.modal'),t.on('shown.bs.modal',function(){n.focus()}),!0===o&&t.modal('show'),t},d.addLocale('en',{OK:'OK',CANCEL:'Cancel',CONFIRM:'OK'}),d}); \ No newline at end of file +!function(e,t){'use strict';'function'==typeof define&&define.amd?define(['jquery'],t):'object'==typeof exports?module.exports=t(require('jquery')):e.bootbox=t(e.jQuery)}(this,function t(p,u){'use strict';var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable('toString'),l=(i=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor']).length,function(e){if('function'!=typeof e&&('object'!=typeof e||null===e))throw new TypeError('Object.keys called on non-object');var t,o,a=[];for(t in e)r.call(e,t)&&a.push(t);if(n)for(o=0;o
",header:"
",footer:'',closeButton:'',form:'
',button:'',option:'',promptMessage:'
',inputs:{text:'',textarea:'',email:'',select:'',checkbox:'
',radio:'
',date:'',time:'',number:'',password:'',range:''}},m={locale:'en',backdrop:'static',animate:!0,className:null,closeButton:!0,show:!0,container:'body',value:'',inputType:'text',swapButtonOrder:!1,centerVertical:!1,multiple:!1,scrollable:!1};function c(e,t,o){return p.extend(!0,{},e,function(e,t){var o=e.length,a={};if(o<1||2').attr('label',t.group)),o=i[t.group]);var a=p(f.option);a.attr('value',t.value).text(t.text),o.append(a)}),v(i,function(e,t){n.append(t)}),n.val(r.value);break;case'checkbox':var l=p.isArray(r.value)?r.value:[r.value];if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "checkbox" requires at least one option');n=p('
'),v(a,function(e,o){if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');var a=p(f.inputs[r.inputType]);a.find('input').attr('value',o.value),a.find('label').append('\n'+o.text),v(l,function(e,t){t===o.value&&a.find('input').prop('checked',!0)}),n.append(a)});break;case'radio':if(r.value!==u&&p.isArray(r.value))throw new Error('prompt with "inputType" set to "radio" requires a single, non-array value for "value"');if(!(a=r.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "radio" requires at least one option');n=p('
');var s=!0;v(a,function(e,t){if(t.value===u||t.text===u)throw new Error('each option needs a "value" property and a "text" property');var o=p(f.inputs[r.inputType]);o.find('input').attr('value',t.value),o.find('label').append('\n'+t.text),r.value!==u&&t.value===r.value&&(o.find('input').prop('checked',!0),s=!1),n.append(o)}),s&&n.find('input[type="radio"]').first().prop('checked',!0)}if(e.append(n),e.on('submit',function(e){e.preventDefault(),e.stopPropagation(),t.find('.bootbox-accept').trigger('click')}),''!==p.trim(r.message)){var c=p(f.promptMessage).html(r.message);e.prepend(c),r.message=e}else r.message=e;return(t=d.dialog(r)).off('shown.bs.modal'),t.on('shown.bs.modal',function(){n.focus()}),!0===o&&t.modal('show'),t},d.addLocale('en',{OK:'OK',CANCEL:'Cancel',CONFIRM:'OK'}),d}); \ No newline at end of file diff --git a/header.txt b/header.txt index 01e0d02c..200d1d0a 100644 --- a/header.txt +++ b/header.txt @@ -1,5 +1,5 @@ /** - * bootbox.js 5.3.2 + * bootbox.js 5.3.3 * * http://bootboxjs.com/license.txt */ \ No newline at end of file diff --git a/package.json b/package.json index 7c21e920..dc4c3778 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootbox", - "version": "5.3.2", + "version": "5.3.3", "description": "Wrappers for JavaScript alert(), confirm(), prompt(), and other flexible dialogs using the Bootstrap framework", "directories": { "test": "tests" diff --git a/tests/prompt.test.js b/tests/prompt.test.js index a54e82ef..a659ee4f 100644 --- a/tests/prompt.test.js +++ b/tests/prompt.test.js @@ -973,7 +973,7 @@ describe('bootbox.prompt', function () { return expect(this.find('input[type="number"]').attr('placeholder')).to.equal('enter the number'); }); }); - describe('with min value', function () { + describe('with min int value', function () { beforeEach(function () { this.options.min = 0; return this.create(); @@ -982,7 +982,16 @@ describe('bootbox.prompt', function () { return expect(this.find('input[type="number"]').attr('min')).to.equal('0'); }); }); - describe('with max value', function () { + describe('with min decimal value', function () { + beforeEach(function () { + this.options.min = -99.99; + return this.create(); + }); + return it('has correct min value', function () { + return expect(this.find('input[type="number"]').attr('min')).to.equal('-99.99'); + }); + }); + describe('with max int value', function () { beforeEach(function () { this.options.max = 100; return this.create(); @@ -991,7 +1000,16 @@ describe('bootbox.prompt', function () { return expect(this.find('input[type="number"]').attr('max')).to.equal('100'); }); }); - describe('with step value', function () { + describe('with max decimal value', function () { + beforeEach(function () { + this.options.max = 99.99; + return this.create(); + }); + return it('has correct max value', function () { + return expect(this.find('input[type="number"]').attr('max')).to.equal('99.99'); + }); + }); + describe('with step int value', function () { beforeEach(function () { this.options.step = 10; return this.create(); @@ -1000,6 +1018,15 @@ describe('bootbox.prompt', function () { return expect(this.find('input[type="number"]').attr('step')).to.equal('10'); }); }); + describe('with step decimal value', function () { + beforeEach(function () { + this.options.step = 0.01; + return this.create(); + }); + return it('has correct step value', function () { + return expect(this.find('input[type="number"]').attr('step')).to.equal('0.01'); + }); + }); describe('with an invalid min value', function () { beforeEach(function () { this.options.min = 'a'; @@ -1035,6 +1062,14 @@ describe('bootbox.prompt', function () { return expect(this.create).to.throw('"step" must be a valid positive number or the value "any". See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-step for more information.'); }); }); + describe('with an invalid negative step value', function () { + beforeEach(function () { + this.options.step = -1; + }); + return it('throws an error', function () { + return expect(this.create).to.throw('"step" must be a valid positive number or the value "any". See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-step for more information.'); + }); + }); });