fix qr files not working (#9)

* added better debugging to fix text import issue

* add more debugging

* initial sanitize function

* add another check to ensure qr size consistency
This commit is contained in:
Bit 2023-08-20 08:01:23 -07:00 committed by GitHub
parent 87b6e41254
commit 454993f3ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -296,12 +296,40 @@ function getInfoBits(){
return result;
}
/***
*
* Sanitize and verify qr is square before parsing it
*
***/
function sanitizeQrTxt(lines) {
const linesOut = [];
for(let i=0;i<lines.length;i++) {
if(lines[i].length !== 0) {
linesOut.push(lines[i]);
}
else if(i+1 !== lines.length) {
throw "Unexpected empty line file."
}
}
for(let i=0;i<linesOut.length;i++) {
if(linesOut[i].length !== linesOut.length) {
throw `QR line: ${i} width:${linesOut[i].length} does not match QR size: ${linesOut.length}`
}
}
return linesOut;
}
/***
*
* Load Waidotto QR text format
* https://github.com/waidotto/strong-qr-decoder
***/
function loadTxt2Array(lines) {
function loadTxt2Array(linesIn) {
console.info(lines)
var lines = sanitizeQrTxt(linesIn);
let sz = lines.length;
var data = [];
@ -332,7 +360,7 @@ function loadTxt2Array(lines) {
break;
default:
throw "Error invalid text QR caracters"
throw `Error invalid text QR caracter: ${lines[i][j]}; from: ${i}x${j}`
}
}
}