提交 97da0517 编写于 作者: N naoto

7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field

Reviewed-by: srl
上级 71354c78
......@@ -1168,7 +1168,7 @@ public final class Locale implements Cloneable, Serializable {
boolean e = (_extensions.getID().length() != 0);
StringBuilder result = new StringBuilder(_baseLocale.getLanguage());
if (r || (l && v)) {
if (r || (l && (v || s || e))) {
result.append('_')
.append(_baseLocale.getRegion()); // This may just append '_'
}
......
......@@ -43,7 +43,7 @@ import java.util.Set;
/**
* @test
* @bug 6875847
* @bug 6875847 6992272 7002320 7015500 7023613
* @summary test API changes to Locale
*/
public class LocaleEnhanceTest extends LocaleTestFmwk {
......@@ -83,7 +83,7 @@ public class LocaleEnhanceTest extends LocaleTestFmwk {
"en-Latn-US-NewYork", "en_US_NewYork_#Latn",
"en-Latn-US", "en_US_#Latn",
"en-Latn-NewYork", "en__NewYork_#Latn", // double underscore
"en-Latn", "en_#Latn",
"en-Latn", "en__#Latn", // double underscore
"en-US-NewYork", "en_US_NewYork",
"en-US", "en_US",
"en-NewYork", "en__NewYork", // double underscore
......@@ -1259,6 +1259,22 @@ public class LocaleEnhanceTest extends LocaleTestFmwk {
}
}
public void testBug7023613() {
String[][] testdata = {
{"en-Latn", "en__#Latn"},
{"en-u-ca-japanese", "en__#u-ca-japanese"},
};
for (String[] data : testdata) {
String in = data[0];
String expected = (data.length == 1) ? data[0] : data[1];
Locale loc = Locale.forLanguageTag(in);
String out = loc.toString();
assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out);
}
}
///
/// utility asserts
///
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册