kazuhikoarase / qrcode-generator

QR Code Generator implementation in JavaScript, Java and more.
https://kazuhikoarase.github.io/qrcode-generator/js/demo/
MIT License
2.1k stars 674 forks source link

Incorrect code generation for some text #90

Closed artfulsage closed 4 years ago

artfulsage commented 4 years ago

Hello. I have encountered a problem with incorrect code generation for some string.

Code for ST0011|пр. Первомайский is decoded correctly. And code for ST00011|пр. Первомайский is strangely decoded incorrectly to ST00011|РїСЂ. Первомайский.

This is just the same as here https://github.com/soldair/node-qrcode/issues/235

It can be reproduced on demo page https://kazuhikoarase.github.io/qrcode-generator/js/demo/ with default params.

kazuhikoarase commented 4 years ago

Hi, I could not reproduce it. My phone had read it correctly.

image

artfulsage commented 4 years ago

Yes! You are right! I have just tried another one scanner and it reads code correctly. Well in fact that's really sad because I don't know which one users will use. But anyway please excuse for troubling.

kazuhikoarase commented 4 years ago

I couldn't reproduce it but found that where they come from. The qrcode encoder generates a pattern in UTF-8. But your scanner seems read it in not UTF-8 but CP1251.

https://ideone.com/teuUBm

System.out.println(new String("ST0011|пр. Первомайский".getBytes("UTF-8"), "CP1251") );
System.out.println(new String("ST00011|пр. Первомайский".getBytes("UTF-8"), "CP1251") );        
ST0011|пр. Первомайский
ST00011|пр. Первомайский

https://en.wikipedia.org/wiki/Windows-1251

artfulsage commented 4 years ago

Thanks for your investigation! I have found that for scanner prefix ST00011 means CP1251 and ST00012 means UTF-8. And so obviously ST0011 means nothing and scanner chooses encoding by itself. I did not know that. I very appreciate your help.