Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows "cannot find encoding ISO 8859-1" #18

Closed
EyeCon opened this issue Sep 8, 2022 · 14 comments
Closed

Windows "cannot find encoding ISO 8859-1" #18

EyeCon opened this issue Sep 8, 2022 · 14 comments
Labels
bug This ISSUE mentions something not working.

Comments

@EyeCon
Copy link

EyeCon commented Sep 8, 2022

As I was trying to run the example code given in the docs:

import QRgen
let urlQR = newQR("https://my-url.domain")
urlQR.printTerminal

...I get the error:

Error: unhandled exception: cannot find encoding ISO 8859-1 [EncodingError]
Error: execution of an external program failed: 'C:\Users\EyeCon\nimcache\qrgentest1_r\qrgentest1_99D5382AA8D22F6EB0B2F4D3D76FCB54F9ECD0A3.exe'

I am on Windows on Nim devel. I installed QRgen via nimble with nimble install qrgen.

@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

Encoding iirc uses the OS to change the encoding of a string, in this case UTF-8 to ISO 8859-1, which is what the QR spec specifies to use when encoding byte mode strings. Seems like windows does not support that encoding? I will research about it later since today I won't be home sry.

@aruZeta aruZeta changed the title The example code doesn't run on Windows ("cannot find encoding ISO 8859-1") Windows "cannot find encoding ISO 8859-1" Sep 9, 2022
@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

Seems like Windows 1252 is the same as ISO 8859-1, I'm not sure, but if you can try it and find out it would be nice.

@aruZeta aruZeta added the bug This ISSUE mentions something not working. label Sep 9, 2022
@enthus1ast
Copy link
Contributor

enthus1ast commented Sep 9, 2022

For me it works when i change:

template encodeByteModeData(self: var EncodedQRCode, data: string) =
  ## Encodes `data` via the byte mode encoding algorithm.
  # for c in convert(data, "ISO 8859-1", "UTF-8"):
  for c in convert(data, "Windows-1252", "UTF-8"):
    self.data.add cast[uint8](c), 8

@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

For me it works when i change:

template encodeByteModeData(self: var EncodedQRCode, data: string) =
  ## Encodes `data` via the byte mode encoding algorithm.
  # for c in convert(data, "ISO 8859-1", "UTF-8"):
  for c in convert(data, "Windows-1252", "UTF-8"):
    self.data.add cast[uint8](c), 8

Nice! Then the solution will be to just use a when block for windows with that code, will make the commit when I get home, or maybe you can do a PR (to develop).

@enthus1ast
Copy link
Contributor

enthus1ast commented Sep 9, 2022

it seems that there is no "correct" way to encode stuff.
I've google a little and saw that alot scanners use heuristic to find the correct encoding anyhow.
I just disabled the (re)encoding in my branch, and my phone was able to read a string like "hallöäüд" correctly.

Some discussions i found: https://stackoverflow.com/questions/9699657/is-utf-8-the-encoding-of-choice-for-qr-codes-with-non-ascii-chars-by-now

To be honest, i would just use utf-8, or maybe just add an option to disable reencoding completely.

@EyeCon
Copy link
Author

EyeCon commented Sep 9, 2022

Please make UTF-8 the default. It is the most used one by the modern operating systems, and has the most coverage anyway.

@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

it seems that there is no "correct" way to encode stuff.
I've google a little and saw that alot scanners use heuristic to find the correct encoding anyhow.
I just disabled the (re)encoding in my branch, and my phone was able to read a string like "hallöäüд" correctly.

Some discussions i found: https://stackoverflow.com/questions/9699657/is-utf-8-the-encoding-of-choice-for-qr-codes-with-non-ascii-chars-by-now

To be honest, i would just use utf-8, or maybe just add an option to disable reencoding completely.

Byte mode is supposed to work with UTF-8 too, the problem I read about is that not all scanners support UTF-8 in byte mode, but tbh I'm not sure and just followed what thonky's website said.

@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

Hmm as that stack overflow says it might be better to just stick with UTF-8

@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

Please make UTF-8 the default. It is the most used one by the modern operating systems, and has the most coverage anyway.

Yh, that's what seems we will do, and it's an easy fix by just removing the encode line.

@aruZeta aruZeta mentioned this issue Sep 9, 2022
aruZeta added a commit that referenced this issue Sep 9, 2022
This also fixes not being able to compile the lib to the JS backend.

Fixes: #18
Fixes: #20
@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

The last commit should fix the issue, if there still are problems, reopen this issue.

@aruZeta aruZeta closed this as completed Sep 9, 2022
@aruZeta
Copy link
Owner

aruZeta commented Sep 9, 2022

Forgot to add: I'm releasing in a moment v1.0.1 with the fix.

@EyeCon
Copy link
Author

EyeCon commented Sep 9, 2022

Thanks! I'll try it when I can.

@EyeCon
Copy link
Author

EyeCon commented Sep 10, 2022

Version 1.0.1 fixes the issue. I tried with many characters outside the 8859-1 or cp1252 range and three different decoders recognized them with no problems.

Thank you for the library, I'll be using it a lot!

@aruZeta
Copy link
Owner

aruZeta commented Sep 10, 2022

Nice! Thanks for bringing the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This ISSUE mentions something not working.
Projects
None yet
Development

No branches or pull requests

3 participants