From 458575184d6f72eb2d6ad27b2c84b706fba43a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Nied=C5=BAwiedzi=C5=84ski?= Date: Sat, 31 Aug 2019 21:29:50 +0200 Subject: [PATCH] Fix #1244 Add error throw on a negative column index --- bits/27_csfutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bits/27_csfutils.js b/bits/27_csfutils.js index 8a087d7..495e5db 100644 --- a/bits/27_csfutils.js +++ b/bits/27_csfutils.js @@ -4,7 +4,7 @@ function fix_row(cstr/*:string*/)/*:string*/ { return cstr.replace(/([A-Z]|^)(\d function unfix_row(cstr/*:string*/)/*:string*/ { return cstr.replace(/\$(\d+)$/,"$1"); } function decode_col(colstr/*:string*/)/*:number*/ { var c = unfix_col(colstr), d = 0, i = 0; for(; i !== c.length; ++i) d = 26*d + c.charCodeAt(i) - 64; return d - 1; } -function encode_col(col/*:number*/)/*:string*/ { var s=""; for(++col; col; col=Math.floor((col-1)/26)) s = String.fromCharCode(((col-1)%26) + 65) + s; return s; } +function encode_col(col/*:number*/)/*:string*/ { if(col < 0) throw new Error("invalid column " + col); var s=""; for(++col; col; col=Math.floor((col-1)/26)) s = String.fromCharCode(((col-1)%26) + 65) + s; return s; } function fix_col(cstr/*:string*/)/*:string*/ { return cstr.replace(/^([A-Z])/,"$$$1"); } function unfix_col(cstr/*:string*/)/*:string*/ { return cstr.replace(/^\$([A-Z])/,"$1"); }