mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
HexUtils: fix empty string handling (#1907)
Fixes #1903 Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
@@ -92,6 +92,10 @@ public class HexUtils {
|
||||
* @return the corresponding byte array
|
||||
*/
|
||||
public static byte[] hexToBytes(String hexString, String delimiter) {
|
||||
if (hexString.isEmpty()) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
// first convert to upper case to ease the rest
|
||||
String ucHexString = hexString.toUpperCase();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -62,4 +62,12 @@ public class HexUtilsTest {
|
||||
byte[] result = HexUtils.hexToBytes("41-:-42-:-43-:-44", "-:-");
|
||||
assertEquals("ABCD", new String(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyByteArray() {
|
||||
final byte[] input = new byte[0];
|
||||
final String str = HexUtils.bytesToHex(input);
|
||||
final byte[] output = HexUtils.hexToBytes(str);
|
||||
assertArrayEquals(input, output);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user