g0dkar / qrcode-kotlin

QRCode Generator implemented in pure Kotlin
https://qrcodekotlin.com/
MIT License
172 stars 16 forks source link

Crash on QrCode with number only #1

Closed pvarry closed 2 years ago

pvarry commented 2 years ago

Hello, first thanks for this library, it's nice to see light Kotlin code :+1:

Describe the bug A got the flowing crash running this :

QRCode("20333").encode()
    java.lang.StringIndexOutOfBoundsException: length=5; index=6
        at java.lang.String.substring(String.java:2060)
        at kotlin.text.StringsKt__StringsKt.substring(Strings.kt:393)
        at io.github.g0dkar.qrcode.internals.QRNumber.write(QRData.kt:137)
        at io.github.g0dkar.qrcode.QRCode.createData(QRCode.kt:353)
        at io.github.g0dkar.qrcode.QRCode.encode(QRCode.kt:250)
        at io.github.g0dkar.qrcode.QRCode.encode$default(QRCode.kt:231)

To Reproduce Steps to reproduce the behavior. For example:

Simply run the Kotlin code.

Additional context I tested this on a physical device (Google Pixel XL) and on a emulator (Pixel 4 API 30), and on both I got this crash.

If I run the folowing Kotlin code I didn't get the crash, but the QrCode is not what I want

QRCode("20333 ").encode()
g0dkar commented 2 years ago

Heya! Thanks for opening the issue! I'll jump right into it!

It's been a hectic couple of weeks, so I didn't have time to finish writing all the proper tests yet ^^

g0dkar commented 2 years ago

@pvarry could you try again with version 1.1.1? I'll see the other issue next!

pvarry commented 2 years ago

I tried the new version and it work perfectly, thanks you !!