Skip to content

Commit 11c3961

Browse files
committed
Fix JSON parsing of unicode escapes
1 parent 4082b77 commit 11c3961

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

java/client/src/org/openqa/selenium/json/JsonInput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.io.Closeable;
2121
import java.io.IOException;
22-
import java.io.StringReader;
2322
import java.io.UncheckedIOException;
2423
import java.lang.reflect.Type;
2524
import java.math.BigDecimal;
@@ -388,7 +387,7 @@ private void readEscape(StringBuilder builder) {
388387
result += digit * multiplier;
389388
multiplier /= 16;
390389
}
391-
builder.append(result);
390+
builder.append((char) result);
392391
break;
393392

394393
case '/':

java/client/test/org/openqa/selenium/json/JsonInputTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertFalse;
2222
import static org.junit.Assert.assertNull;
2323
import static org.junit.Assert.assertTrue;
24+
import static org.openqa.selenium.json.Json.MAP_TYPE;
2425

2526
import com.google.common.collect.ImmutableList;
2627
import com.google.common.collect.ImmutableMap;
@@ -29,6 +30,7 @@
2930
import org.junit.Test;
3031

3132
import java.io.StringReader;
33+
import java.util.Map;
3234

3335
public class JsonInputTest {
3436

@@ -187,6 +189,17 @@ public void nestedMapIsFine() {
187189
input.endObject();
188190
}
189191

192+
@Test
193+
public void shouldDecodeUnicodeEscapesProperly() {
194+
String raw = "{\"text\": \"\\u003Chtml\"}";
195+
196+
try (JsonInput in = new JsonInput(new StringReader(raw), new JsonTypeCoercer())) {
197+
Map<String, Object> map = in.read(MAP_TYPE);
198+
199+
assertEquals("<html", map.get("text"));
200+
}
201+
}
202+
190203
private JsonInput newInput(Object toParse) {
191204
String raw = new Gson().toJson(toParse);
192205
StringReader reader = new StringReader(raw);

0 commit comments

Comments
 (0)