From 56122ba5c5f08ed3182bfe0cbc973ee4f1e6c3f9 Mon Sep 17 00:00:00 2001 From: ogesaku Date: Fri, 3 May 2024 23:54:25 +0200 Subject: [PATCH] Fix matching 0 prefixes in file loaders --- .../java/com/coditory/quark/i18n/loader/I18nPathPattern.java | 2 +- .../com/coditory/quark/i18n/loader/I18nPathPatternSpec.groovy | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/coditory/quark/i18n/loader/I18nPathPattern.java b/src/main/java/com/coditory/quark/i18n/loader/I18nPathPattern.java index c43e0bf..9baa265 100644 --- a/src/main/java/com/coditory/quark/i18n/loader/I18nPathPattern.java +++ b/src/main/java/com/coditory/quark/i18n/loader/I18nPathPattern.java @@ -165,7 +165,7 @@ private I18nPath extractPath(Matcher matcher) { String prefix = null; if (activeGroups.containsKey(PREFIXES_GROUP_MARKER)) { String prefixesMatch = matcher.group("prefixes"); - if (prefixesMatch != null && !prefixesMatch.equals("/")) { + if (prefixesMatch != null && !prefixesMatch.isEmpty() && !prefixesMatch.equals("/")) { prefix = prefixesMatch.substring(0, prefixesMatch.length() - 1); } } diff --git a/src/test/groovy/com/coditory/quark/i18n/loader/I18nPathPatternSpec.groovy b/src/test/groovy/com/coditory/quark/i18n/loader/I18nPathPatternSpec.groovy index 0f8bf87..3659f35 100644 --- a/src/test/groovy/com/coditory/quark/i18n/loader/I18nPathPatternSpec.groovy +++ b/src/test/groovy/com/coditory/quark/i18n/loader/I18nPathPatternSpec.groovy @@ -42,6 +42,7 @@ class I18nPathPatternSpec extends Specification { "/abc/*.json" | "/abc/x.json.json" "/abc/*.*.json" | "/abc/x.xml.json" // capturing groups + "/abc/{prefixes}/i18n.json" | "/abc/i18n.json" "/abc/{prefixes}/*.json" | "/abc/def/xxx.json" "{prefixes}/*.json" | "/abc/def/xxx.json" "/abc/**/i18n_{locale}.json" | "/abc/def/i18n_pl-PL.json" @@ -135,11 +136,12 @@ class I18nPathPatternSpec extends Specification { when: I18nPathGroups matched = matchGroups(pattern, input) then: - matched.path() == I18nPath.of(path) + matched.path() == (path == null ? null : I18nPath.of(path)) where: pattern | input || path "**/i18n-{prefix}.yml" | "/abc/i18n-homepage.yml" || "homepage" "/i18n/{prefix}.yml" | "/i18n/glossary.yml" || "glossary" + "com/i18n/{prefixes}/i18n.yml" | "com/i18n/i18n.yml" || null "com/i18n/{prefixes}/i18n.yml" | "com/i18n/abc/def/i18n.yml" || "abc.def" "com/i18n/{prefixes}/i18n-{prefix}.yml" | "com/i18n/abc/def/i18n-base.yml" || "abc.def.base" "com/i18n/{prefixes}/xxx/i18n.yml" | "com/i18n/abc/def/xxx/i18n.yml" || "abc.def"