QR8bitByte: address #41
input strings with unicode characters at high code points were not encoded correctly, such as "🔝"
This commit is contained in:
parent
7ee4b870c7
commit
686308ef0d
|
@ -19,7 +19,8 @@
|
||||||
"react-redux": "^7.2.0",
|
"react-redux": "^7.2.0",
|
||||||
"react-scripts": "3.4.1",
|
"react-scripts": "3.4.1",
|
||||||
"redux": "^4.0.5",
|
"redux": "^4.0.5",
|
||||||
"serialize-javascript": "^3.1.0"
|
"serialize-javascript": "^3.1.0",
|
||||||
|
"utf8": "^3.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|
|
@ -13,42 +13,18 @@
|
||||||
// http://www.denso-wave.com/qrcode/faqpatent-e.html
|
// http://www.denso-wave.com/qrcode/faqpatent-e.html
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
const utf8 = require('utf8');
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
function QR8bitByte(data) {
|
function QR8bitByte(data) {
|
||||||
this.mode = QRMode.MODE_8BIT_BYTE;
|
this.mode = QRMode.MODE_8BIT_BYTE;
|
||||||
this.data = data;
|
this.data = utf8.encode(data);
|
||||||
this.parsedData = [];
|
this.parsedData = [];
|
||||||
|
|
||||||
// Added to support UTF-8 Characters
|
// Added to support UTF-8 Characters
|
||||||
for (var i = 0, l = this.data.length; i < l; i++) {
|
for (var i = 0, l = this.data.length; i < l; i++) {
|
||||||
var byteArray = [];
|
|
||||||
var code = this.data.charCodeAt(i);
|
var code = this.data.charCodeAt(i);
|
||||||
|
this.parsedData.push(code);
|
||||||
if (code > 0x10000) {
|
|
||||||
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
|
|
||||||
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
|
|
||||||
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
|
|
||||||
byteArray[3] = 0x80 | (code & 0x3F);
|
|
||||||
} else if (code > 0x800) {
|
|
||||||
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
|
|
||||||
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
|
|
||||||
byteArray[2] = 0x80 | (code & 0x3F);
|
|
||||||
} else if (code > 0x80) {
|
|
||||||
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
|
|
||||||
byteArray[1] = 0x80 | (code & 0x3F);
|
|
||||||
} else {
|
|
||||||
byteArray[0] = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parsedData.push(byteArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
|
|
||||||
|
|
||||||
if (this.parsedData.length != this.data.length) {
|
|
||||||
this.parsedData.unshift(191);
|
|
||||||
this.parsedData.unshift(187);
|
|
||||||
this.parsedData.unshift(239);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue