summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-15 21:07:47 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-15 23:36:36 -0500
commit4b8268f843b0da1cfe1995d93a0b1f95faccc454 (patch)
treef7ab0a390cefa0d5fe94e585fbededa6d36c10db
parent2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2 (diff)
catalog: fix language detection
Detection would fail if language was not specified in the filename but a dot appeared somewhere higher in the path.
-rw-r--r--src/journal/catalog.c4
-rw-r--r--src/journal/test-catalog.c12
2 files changed, 11 insertions, 5 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index 2be81aa2f7..e3a3354ab7 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -150,10 +150,10 @@ int catalog_file_lang(const char* filename, char **lang) {
return 0;
beg = end - 1;
- while (beg > filename && *beg != '.')
+ while (beg > filename && *beg != '.' && *beg != '/' && end - beg < 32)
beg --;
- if (beg <= filename || end <= beg + 1 || end - beg > 32)
+ if (*beg != '.' || end <= beg + 1)
return 0;
_lang = strndup(beg + 1, end - beg - 1);
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 863b9f4b51..ffe180265b 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -121,7 +121,7 @@ static void test_catalog_update(void) {
}
static void test_catalog_file_lang(void) {
- _cleanup_free_ char *lang = NULL, *lang2 = NULL, *lang3 = NULL;
+ _cleanup_free_ char *lang = NULL, *lang2 = NULL, *lang3 = NULL, *lang4 = NULL;
assert_se(catalog_file_lang("systemd.de_DE.catalog", &lang) == 1);
assert_se(streq(lang, "de_DE"));
@@ -140,6 +140,12 @@ static void test_catalog_file_lang(void) {
assert_se(catalog_file_lang("systemd.0123456789012345678901234567890.catalog", &lang3) == 1);
assert_se(streq(lang3, "0123456789012345678901234567890"));
+
+ assert_se(catalog_file_lang("/x/y/systemd.catalog", &lang4) == 0);
+ assert_se(lang4 == NULL);
+
+ assert_se(catalog_file_lang("/x/y/systemd.ru_RU.catalog", &lang4) == 1);
+ assert_se(streq(lang4, "ru_RU"));
}
int main(int argc, char *argv[]) {
@@ -150,6 +156,8 @@ int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
+ test_catalog_file_lang();
+
test_catalog_importing();
test_catalog_update();
@@ -166,7 +174,5 @@ int main(int argc, char *argv[]) {
if (database)
unlink(database);
- test_catalog_file_lang();
-
return 0;
}