mirror of
https://github.com/Merricx/qrazybox.git
synced 2024-11-24 11:42:58 +01:00
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:
parent
87b6e41254
commit
454993f3ca
1 changed files with 30 additions and 2 deletions
32
js/main.js
32
js/main.js
|
@ -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}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue