Skip to content

Commit

Permalink
fix: double asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Jan 18, 2025
1 parent 839af9d commit bb6f298
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) {
throw new NullPointerException("null args in replaceFileDependentPlaceholders()");
}
String fileName = file.getName();
String filePath = Utils.toUnixPath(file.getPath());
String fileNameWithoutExt = FilenameUtils.removeExtension(fileName);
String fileExt = FilenameUtils.getExtension(fileName);
String tempBasePath = basePath;
Expand All @@ -211,12 +212,12 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) {
String prefixFormat = StringUtils.substringBefore(toFormat, "**");
String substringAfter = StringUtils.substringAfter(toFormat, "**");
//making sure "substringAfter" has full file path part that goes after "**"
if (substringAfter.length() > 1 && !file.getPath().endsWith(substringAfter) && file.getPath().contains(substringAfter)) {
String[] parts = file.getPath().split(substringAfter);
if (substringAfter.length() > 1 && !filePath.endsWith(substringAfter) && filePath.contains(substringAfter)) {
String[] parts = filePath.split(substringAfter);
substringAfter = Utils.joinPaths(substringAfter, parts[parts.length - 1]);
}
String postfix = Utils.getParentDirectory(substringAfter);
String prefix = prefixFormat.length() > 1 && file.getPath().contains(prefixFormat) ? StringUtils.substringBefore(fileParent, Utils.noSepAtStart(prefixFormat)) : "";
String prefix = prefixFormat.length() > 1 && filePath.contains(prefixFormat) ? StringUtils.substringBefore(fileParent, Utils.noSepAtStart(prefixFormat)) : "";
String doubleAsterisks =
StringUtils.removeStart(Utils.noSepAtStart(StringUtils.removeStart(fileParent, prefix)), Utils.noSepAtEnd(Utils.noSepAtStart(prefixFormat)));
doubleAsterisks = postfix.length() > 1 ? StringUtils.removeEnd(doubleAsterisks, Utils.noSepAtEnd(postfix)) : doubleAsterisks;
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/crowdin/cli/utils/PlaceholderUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ static Stream<Arguments> testMainFunctionality() {
new File[] {new File("resources/test/main/settings/default/test/en/messages.xml")},
Utils.normalizePath("**/default/test/%two_letters_code%"),
new String[] {Utils.normalizePath("resources/test/main/settings/default/test/en")}
),
arguments(// How to treat double asterisks in the middle
new Language[] {LanguageBuilder.ENG.build()},
new Language[] {LanguageBuilder.ENG.build()},
new File[] {new File("src/app/resources/test/main/settings/default/test/en/messages.xml")},
Utils.normalizePath("src/app/**/default/test/%two_letters_code%"),
new String[] {Utils.normalizePath("src/app/resources/test/main/settings/default/test/en")}
)
);
}
Expand Down

0 comments on commit bb6f298

Please sign in to comment.