From 44d5ea454c75b57235c277dec55f974a6674eb54 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Wed, 23 Feb 2022 12:58:57 -0800 Subject: [PATCH] Increase white-space tolerance when importing avatars from msgbase TARDIS (Quarkware BBS, the Ruby BBS), uses just \n for QWK message line deliniation, but we were expected \r\n terminated lines here. Also, apparently there was trailing white-space on the "json-end" line, so handle that case too. --- exec/avatars.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/exec/avatars.js b/exec/avatars.js index e54171ea30..c8c85b5ad8 100644 --- a/exec/avatars.js +++ b/exec/avatars.js @@ -31,18 +31,19 @@ function parse_user_msg(text) var json_end; // Terminate at tear-line - text=text.split("\r\n"); + text=text.split("\n"); for(i=0; i<text.length; i++) { - if(text[i]=="---" || text[i].substring(0,4)=="--- ") + if(text[i].trimRight()=="---" || text[i].substring(0,4)=="--- ") break; } text.length=i; // Parse JSON block for(i=0; i<text.length; i++) { - if(text[i].toLowerCase()=="json-begin") + print(i + ": " + text[i]); + if(text[i].trimRight().toLowerCase()=="json-begin") json_begin=i+1; - else if(text[i].toLowerCase()=="json-end") + else if(text[i].trimRight().toLowerCase()=="json-end") json_end=i; } if(json_begin && json_end > json_begin) { @@ -55,6 +56,8 @@ function parse_user_msg(text) } return false; } + alert("invalid or missing JSON block, length: " + text.length + + ", begin: " + json_begin + ", end: " + json_end); return false; } @@ -65,24 +68,26 @@ function parse_file_msg(text) var bin_end; // Terminate at tear-line - text=text.split("\r\n"); + text=text.split("\n"); for(i=0; i<text.length; i++) { - if(text[i]=="---" || text[i].substring(0,4)=="--- ") + if(text[i].trimRight()=="---" || text[i].substring(0,4)=="--- ") break; } text.length=i; // Parse JSON block for(i=0; i<text.length; i++) { - if(text[i].toLowerCase()=="bin-lz-begin") + if(text[i].trimRight().toLowerCase()=="bin-lz-begin") bin_begin=i+1; - else if(text[i].toLowerCase()=="bin-lz-end") + else if(text[i].trimRight().toLowerCase()=="bin-lz-end") bin_end=i; } if(bin_begin && bin_end > bin_begin) { text = text.splice(bin_begin, bin_end-bin_begin); return LZString.decompressFromBase64(text.join('').replace(/\s+/g, '')); } + alert("invalid or missing bin-lz block, length: " + text.length + + ", begin: " + bin_begin + ", end: " + bin_end); return false; } @@ -278,9 +283,8 @@ function import_from_msgbase(msgbase, import_ptr, limit, all) if(hdr.to.toLowerCase() == user_avatars.toLowerCase()) { var l; var avatars = parse_user_msg(body); - if(!avatars) - continue; - success = import_netuser_list(hdr, decompress_list(avatars)); + if(avatars) + success = import_netuser_list(hdr, decompress_list(avatars)); } else { // Shared avatars success = import_shared_file(hdr, body); -- GitLab