Skip to content

Commit

Permalink
Correct decode of char sequence containing a lower-case 'g' character
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Apr 28, 2023
1 parent 855b9e4 commit 55b6b92
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.rst
Expand Up @@ -8,6 +8,16 @@ Version 1.1

Minor release of GDSC Test.

.. list-table::
:widths: 30 70
:header-rows: 1

* - Change
- Description

* - Fix
- Correct decode of hex char sequence containing a lower-case 'g' character.

Version 1.0.2
-------------

Expand Down
Expand Up @@ -158,6 +158,6 @@ public static byte[] decode(CharSequence string) {
* @return the hex number
*/
private static byte mapToHexNumber(int ch) {
return (ch > DECODE_TABLE.length) ? UNMAPPED : DECODE_TABLE[ch];
return ch < DECODE_TABLE.length ? DECODE_TABLE[ch] : UNMAPPED;
}
}
Expand Up @@ -44,8 +44,12 @@ void testDecodeWithBadInput() {
Assertions.assertArrayEquals(empty, Hex.decode(null), "Null input");
Assertions.assertArrayEquals(empty, Hex.decode(""), "Empty input");
Assertions.assertArrayEquals(empty, Hex.decode("j"), "Bad single character");
Assertions.assertArrayEquals(empty, Hex.decode("abcsfp678"),
"Bad single character in larger string");
Assertions.assertArrayEquals(empty, Hex.decode("/0123456789ABCDEFabcdef"), "Bad char");
Assertions.assertArrayEquals(empty, Hex.decode("0123456789:ABCDEFabcdef"), "Bar char");
Assertions.assertArrayEquals(empty, Hex.decode("0123456789@ABCDEFabcdef"), "Bar char");
Assertions.assertArrayEquals(empty, Hex.decode("0123456789ABCDEFGabcdef"), "Bar char");
Assertions.assertArrayEquals(empty, Hex.decode("0123456789ABCDEF`abcdef"), "Bar char");
Assertions.assertArrayEquals(empty, Hex.decode("0123456789ABCDEFabcdefg"), "Bar char");
}

@Test
Expand Down

0 comments on commit 55b6b92

Please sign in to comment.