[core] Make sure, a language with empty version selects the default version

This commit is contained in:
Andreas Dangel
2017-12-15 12:02:04 +01:00
parent d6a9be55a8
commit 5eb3ecd5ad
2 changed files with 16 additions and 1 deletions

View File

@ -14,6 +14,8 @@ import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.apache.commons.lang3.StringUtils;
/**
* Created by christoferdutz on 20.09.14.
*/
@ -90,7 +92,7 @@ public final class LanguageRegistry {
String version;
String terseName;
if (terseNameAndVersion.contains(" ")) {
version = terseNameAndVersion.substring(terseNameAndVersion.lastIndexOf(' ') + 1);
version = StringUtils.trimToNull(terseNameAndVersion.substring(terseNameAndVersion.lastIndexOf(' ') + 1));
terseName = terseNameAndVersion.substring(0, terseNameAndVersion.lastIndexOf(' '));
} else {
version = null;

View File

@ -17,4 +17,17 @@ public class LanguageRegistryTest {
// available language now -> DummyLanguage
Assert.assertSame(DummyLanguageModule.class, defaultLanguage.getClass());
}
@Test
public void getDefaultVersionLanguageTest() {
LanguageVersion dummy12 = LanguageRegistry.findLanguageVersionByTerseName("dummy 1.2");
Assert.assertNotNull(dummy12);
Language dummy = LanguageRegistry.findLanguageByTerseName("dummy");
LanguageVersion dummyDefault = dummy.getDefaultVersion();
LanguageVersion dummyDefault2 = LanguageRegistry.findLanguageVersionByTerseName("dummy ");
Assert.assertNotNull(dummyDefault2);
Assert.assertSame(dummyDefault, dummyDefault2);
}
}