Skip to content

Commit cb2d835

Browse files
authored
when range is a single cell, s and e hold the same references and thus modifying properties of one affects the other (#2026)
1 parent 716bef4 commit cb2d835

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bits/27_csfutils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function encode_cell(cell/*:CellAddress*/)/*:string*/ {
2626
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
2727
return s + (cell.r + 1);
2828
}
29-
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
29+
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; }
3030
/*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */
3131
function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ {
3232
if(typeof ce === 'undefined' || typeof ce === 'number') {

test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,19 @@ describe('API', function() {
768768
]);
769769
if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' });
770770
});
771+
it('decode_range', function() {
772+
var _c = "ABC", _r = "123", _C = "DEF", _R = "456";
773+
774+
var r = X.utils.decode_range(_c + _r + ":" + _C + _R);
775+
assert(r.s != r.e);
776+
assert.equal(r.s.c, X.utils.decode_col(_c)); assert.equal(r.s.r, X.utils.decode_row(_r));
777+
assert.equal(r.e.c, X.utils.decode_col(_C)); assert.equal(r.e.r, X.utils.decode_row(_R));
778+
779+
r = X.utils.decode_range(_c + _r);
780+
assert(r.s != r.e);
781+
assert.equal(r.s.c, X.utils.decode_col(_c)); assert.equal(r.s.r, X.utils.decode_row(_r));
782+
assert.equal(r.e.c, X.utils.decode_col(_c)); assert.equal(r.e.r, X.utils.decode_row(_r));
783+
});
771784
});
772785

773786
function coreprop(props) {

0 commit comments

Comments
 (0)