mirror of https://github.com/status-im/consul.git
ui: Make sure right trim doesn't try to overtrim (#8171)
This commit is contained in:
parent
deb77f31cb
commit
b2b2cedb06
|
@ -1,4 +1,7 @@
|
||||||
export default function rightTrim(str = '', search = '') {
|
export default function rightTrim(str = '', search = '') {
|
||||||
const pos = str.length - search.length;
|
const pos = str.length - search.length;
|
||||||
|
if (pos >= 0) {
|
||||||
return str.lastIndexOf(search) === pos ? str.substr(0, pos) : str;
|
return str.lastIndexOf(search) === pos ? str.substr(0, pos) : str;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,22 @@ module('Unit | Utility | right trim', function() {
|
||||||
args: ['/a/folder/here/', '/a/folder/here/'],
|
args: ['/a/folder/here/', '/a/folder/here/'],
|
||||||
expected: '',
|
expected: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
args: ['/a/folder/here/', '-'],
|
||||||
|
expected: '/a/folder/here/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: ['/a/folder/here/', 'here'],
|
||||||
|
expected: '/a/folder/here/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: ['here', '/here'],
|
||||||
|
expected: 'here',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: ['/here', '/here'],
|
||||||
|
expected: '',
|
||||||
|
},
|
||||||
].forEach(function(item) {
|
].forEach(function(item) {
|
||||||
const actual = rightTrim(...item.args);
|
const actual = rightTrim(...item.args);
|
||||||
assert.equal(actual, item.expected);
|
assert.equal(actual, item.expected);
|
||||||
|
|
Loading…
Reference in New Issue