From 4ac977654ccc623d31dc82d263910f0883546c3b Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 25 Oct 2019 10:49:57 -0400 Subject: [PATCH 1/2] do not accept bad domain input data --- src/plots/domain.js | 8 ++++++-- test/jasmine/tests/plots_test.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plots/domain.js b/src/plots/domain.js index 343e0c451e4..dd04688049f 100644 --- a/src/plots/domain.js +++ b/src/plots/domain.js @@ -127,6 +127,10 @@ exports.defaults = function(containerOut, layout, coerce, dfltDomains) { } } - coerce('domain.x', dfltX); - coerce('domain.y', dfltY); + var x = coerce('domain.x', dfltX); + var y = coerce('domain.y', dfltY); + + // don't accept bad input data + if(!(x[0] < x[1])) containerOut.domain.x = dfltX; + if(!(y[0] < y[1])) containerOut.domain.y = dfltY; }; diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 2b6e777ae62..443cdb9ad3e 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -13,6 +13,27 @@ describe('Test Plots', function() { 'use strict'; describe('Plots.supplyDefaults', function() { + it('should not accept ranges where the end is not greater than the start', function() { + var gd = { + data: [{ + type: 'pie', + domain: { + x: [0.4, 0], + y: [0.5, 0.5] + }, + values: [1, 2, 3, 4], + labels: ['a', 'b', 'c', 'd'], + text: ['text', 'should', 'be', 'inside'] + }] + }; + + supplyAllDefaults(gd); + expect(gd._fullData[0].domain.x[0]).toBe(0); + expect(gd._fullData[0].domain.y[1]).toBe(1); + expect(gd._fullData[0].domain.x[0]).toBe(0); + expect(gd._fullData[0].domain.y[1]).toBe(1); + }); + it('should not throw an error when gd is a plain object', function() { var height = 100; var gd = { From 74773fb1c28104c896873bf19022d6a871f0b24e Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 25 Oct 2019 15:58:41 -0400 Subject: [PATCH 2/2] add extra slice --- src/plots/domain.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plots/domain.js b/src/plots/domain.js index dd04688049f..abdfbd84a33 100644 --- a/src/plots/domain.js +++ b/src/plots/domain.js @@ -131,6 +131,6 @@ exports.defaults = function(containerOut, layout, coerce, dfltDomains) { var y = coerce('domain.y', dfltY); // don't accept bad input data - if(!(x[0] < x[1])) containerOut.domain.x = dfltX; - if(!(y[0] < y[1])) containerOut.domain.y = dfltY; + if(!(x[0] < x[1])) containerOut.domain.x = dfltX.slice(); + if(!(y[0] < y[1])) containerOut.domain.y = dfltY.slice(); };