Fixed handling of short-form unicode escapes

This commit is contained in:
moandji.ezana 2015-01-22 14:54:50 +02:00
parent 1380c72d48
commit ba84494583
3 changed files with 26 additions and 1 deletions

View file

@ -1,5 +1,8 @@
# toml4j Changelog
## NEXT
* Fixed short-form Unicode escapes
## 0.3.1 / 2014-12-16
* Support for [TOML 0.3.1](https://github.com/toml-lang/toml/tree/v0.3.1) spec
* Pass TOML validator (https://github.com/BurntSushi/toml-test), which uncovered many bugs.

View file

@ -9,7 +9,7 @@ import java.util.regex.Pattern;
class StringConverter implements ValueConverter {
static final StringConverter STRING_PARSER = new StringConverter();
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\[uU](.*)");
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\[uU](.{4})");
@Override
public boolean canConvert(String s) {

View file

@ -0,0 +1,22 @@
package com.moandjiezana.toml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class UnicodeTest {
@Test
public void should_support_short_escape_form() throws Exception {
Toml toml = new Toml().parse("key = \"Jos\u00E9\\nLocation\tSF\"");
assertEquals("José\nLocation\tSF", toml.getString("key"));
}
@Test
public void should_support_unicode_literal() throws Exception {
Toml toml = new Toml().parse("key = \"José LöcÄtion SF\"");
assertEquals("José LöcÄtion SF", toml.getString("key"));
}
}