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

Byte.parseHex(String str) could throw IllegalArgumentException #37

Closed
petrukhnov opened this issue May 10, 2019 · 3 comments
Closed

Byte.parseHex(String str) could throw IllegalArgumentException #37

petrukhnov opened this issue May 10, 2019 · 3 comments
Assignees
Milestone

Comments

@petrukhnov
Copy link

petrukhnov commented May 10, 2019

Byte.parseHex(String str) could throw IllegalArgumentException on malformed string. It is not mentioned in docs or javadoc.

java.lang.IllegalArgumentException: invalid hex string, must be mod 2 == 0
	at at.favre.lib.bytes.BinaryToTextEncoding$Hex.decode(BinaryToTextEncoding.java:108)
	at at.favre.lib.bytes.Bytes.parse(Bytes.java:652)
	at at.favre.lib.bytes.Bytes.parseHex(Bytes.java:603)


@patrickfav
Copy link
Owner

Thanks for reporting, I will add a hint in the javadoc

@patrickfav
Copy link
Owner

patrickfav commented May 23, 2019

On a different thought, since the decoder is very forgiving, I added the feature that it also accepts odd number length strings with auto padding of zero, so currently (ie. next release 1.2.0) it supports:

  • Upper- and lowercase a-f (also mixed case)
  • Prefix with 0x which will be ignored
  • Even and odd number of string length with auto zero padding (ie. 'E3F' is same as '0E3F')

@patrickfav patrickfav added this to the v1.2.0 milestone May 23, 2019
@patrickfav patrickfav self-assigned this May 23, 2019
patrickfav added a commit that referenced this issue May 23, 2019
With auto zero padding (ie. 'E3F' is same as '0E3F'). Also adds
more tests for error cases and improve javadoc

refs #37
@patrickfav
Copy link
Owner

Will be released with 1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants