forked from Qortal/qortal
CHANGED: added translation context path normalization
This commit is contained in:
parent
6bc0eeac4d
commit
d24f1de36a
@ -179,7 +179,7 @@ public class TranslationXmlStreamReader {
|
||||
String value = attribute.getValue();
|
||||
switch(name.toString()) {
|
||||
case TRANSLATION_KEY_ATTRIBUTE_NAME:
|
||||
assureIsValidPathExtension(value);
|
||||
assureIsValidKey(value);
|
||||
path = combinePaths(state.path, value);
|
||||
break;
|
||||
case TRANSLATION_TEMPLATE_ATTRIBUTE_NAME:
|
||||
@ -218,8 +218,13 @@ public class TranslationXmlStreamReader {
|
||||
}
|
||||
}
|
||||
|
||||
private void assureIsValidKey(String value) throws XMLStreamException {
|
||||
if(value.contains("/"))
|
||||
throw new javax.xml.stream.XMLStreamException("Key must not contain /");
|
||||
}
|
||||
|
||||
private String combinePaths(String left, String right) {
|
||||
return Paths.get(left, right).toString();
|
||||
return Paths.get(left, right).normalize().toString();
|
||||
}
|
||||
|
||||
private void assureStartElement(XMLEvent event, String name) throws XMLStreamException {
|
||||
|
@ -59,9 +59,9 @@ public class GlobalizationTests {
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
" <context locale=\"en-GB\">\n" +
|
||||
" <context path=\"path1\">\n" +
|
||||
" <context path=\"path2/path3\">\n" +
|
||||
" <translation key=\"key1\" template=\"1\" />\n" +
|
||||
" <context path=\"path1/\">\n" +
|
||||
" <translation key=\"key1\" template=\"1\" />\n" +
|
||||
" <context path=\"./path2//path3\">\n" +
|
||||
" <translation key=\"key2\" template=\"2\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
@ -69,7 +69,7 @@ public class GlobalizationTests {
|
||||
"</localization>\n";
|
||||
|
||||
List<TranslationEntry> expected = new ArrayList<TranslationEntry>();
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path2/path3/key1", "1"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/key1", "1"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path2/path3/key2", "2"));
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
|
Loading…
Reference in New Issue
Block a user