From cb2d83506e06b4f84eb9e99d09b442f83c99d306 Mon Sep 17 00:00:00 2001 From: Kevin Kerber Date: Fri, 26 Jun 2020 13:16:14 -0700 Subject: [PATCH] when range is a single cell, s and e hold the same references and thus modifying properties of one affects the other (#2026) --- bits/27_csfutils.js | 2 +- test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bits/27_csfutils.js b/bits/27_csfutils.js index 582f49c..de0b8e4 100644 --- a/bits/27_csfutils.js +++ b/bits/27_csfutils.js @@ -26,7 +26,7 @@ function encode_cell(cell/*:CellAddress*/)/*:string*/ { for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; return s + (cell.r + 1); } -function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; } +function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } /*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */ function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ { if(typeof ce === 'undefined' || typeof ce === 'number') { diff --git a/test.js b/test.js index f417fac..75fe8d4 100644 --- a/test.js +++ b/test.js @@ -768,6 +768,19 @@ describe('API', function() { ]); if(assert.deepEqual) assert.deepEqual(data.A2, { l: { Target: 'https://123.com' }, v: 'url', t: 's' }); }); + it('decode_range', function() { + var _c = "ABC", _r = "123", _C = "DEF", _R = "456"; + + var r = X.utils.decode_range(_c + _r + ":" + _C + _R); + assert(r.s != r.e); + assert.equal(r.s.c, X.utils.decode_col(_c)); assert.equal(r.s.r, X.utils.decode_row(_r)); + assert.equal(r.e.c, X.utils.decode_col(_C)); assert.equal(r.e.r, X.utils.decode_row(_R)); + + r = X.utils.decode_range(_c + _r); + assert(r.s != r.e); + assert.equal(r.s.c, X.utils.decode_col(_c)); assert.equal(r.s.r, X.utils.decode_row(_r)); + assert.equal(r.e.c, X.utils.decode_col(_c)); assert.equal(r.e.r, X.utils.decode_row(_r)); + }); }); function coreprop(props) {