Skip to content

Commit 5002d4f

Browse files
committed
fix: handle negative slice indices correctly
- Fixes test failure in svg_text_utils_test.js where slice(0, negative) returned a string instead of empty string (unlike substr). - Fixes similar potential issues in rangeslider/defaults.js and cartesian/axes.js using Math.max(0, ...).
1 parent 2becc65 commit 5002d4f

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/components/rangeslider/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
4545
if(subplots) {
4646
var yIds = subplots.cartesian
4747
.filter(function(subplotId) {
48-
return subplotId.slice(0, subplotId.indexOf('y')) === axisIds.name2id(axName);
48+
return subplotId.slice(0, Math.max(0, subplotId.indexOf('y'))) === axisIds.name2id(axName);
4949
})
5050
.map(function(subplotId) {
5151
return subplotId.slice(subplotId.indexOf('y'), subplotId.length);

src/lib/svg_text_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ exports.plainText = function(_str, opts) {
458458
}
459459

460460
if(len > eLen) {
461-
newParts.push(p.slice(0, pLen2 - eLen) + ellipsis);
461+
newParts.push(p.slice(0, Math.max(0, pLen2 - eLen)) + ellipsis);
462462
} else {
463463
newParts.push(p.slice(0, pLen2));
464464
}

src/plots/cartesian/axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ function numFormat(v, ax, fmtoverride, hover) {
21632163
if(tickRound === 0) v = String(Math.floor(v));
21642164
else if(tickRound < 0) {
21652165
v = String(Math.round(v));
2166-
v = v.slice(0, v.length + tickRound);
2166+
v = v.slice(0, Math.max(0, v.length + tickRound));
21672167
for(var i = tickRound; i < 0; i++) v += '0';
21682168
} else {
21692169
v = String(v);

0 commit comments

Comments
 (0)