Skip to content

Commit

Permalink
fix: double asterisks in paths
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Mar 13, 2024
1 parent c280608 commit db33a56
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class PlaceholderUtil {
private static final String ESCAPE_ASTERISK = isWindows() ? "^*" : "\\*";
private static final String ESCAPE_ASTERISK_REGEX = "\\*";
private static final String ESCAPE_ASTERISK_PLACEHOLDER = "{ESCAPE_ASTERISK}";
private static final String ESCAPE_ASTERISK_REPLACEMENT_FROM = ".+" + Utils.PATH_SEPARATOR;
private static final String ESCAPE_ASTERISK_REPLACEMENT_FROM = ".+" + Utils.PATH_SEPARATOR_REGEX;
private static final String ESCAPE_ASTERISK_REPLACEMENT_TO = "(.+" + Utils.PATH_SEPARATOR_REGEX + ")?";

private List<Language> supportedLanguages;
Expand Down Expand Up @@ -193,10 +193,12 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) {
toFormat = toFormat.replace("/", File.separator);

if (toFormat.contains("**")) {
String prefix = StringUtils.substringBefore(toFormat, "**");
prefix = prefix.length() > 1 && file.getPath().contains(prefix) ? StringUtils.substringBefore(fileParent, Utils.noSepAtStart(prefix)) : "";
String prefixFormat = StringUtils.substringBefore(toFormat, "**");
String postfix = StringUtils.removeEnd(StringUtils.substringAfter(toFormat, "**"), fileName);
String prefix = prefixFormat.length() > 1 && file.getPath().contains(prefixFormat) ? StringUtils.substringBefore(fileParent, Utils.noSepAtStart(prefixFormat)) : "";
String doubleAsterisks =
StringUtils.removeStart(Utils.noSepAtStart(StringUtils.removeStart(fileParent, prefix)), Utils.noSepAtEnd(Utils.noSepAtStart(StringUtils.substringBefore(toFormat, "**"))));
StringUtils.removeStart(Utils.noSepAtStart(StringUtils.removeStart(fileParent, prefix)), Utils.noSepAtEnd(Utils.noSepAtStart(prefixFormat)));
doubleAsterisks = postfix.length() > 1 ? StringUtils.removeEnd(doubleAsterisks, Utils.noSepAtEnd(postfix)) : doubleAsterisks;
toFormat = toFormat.replace("**", doubleAsterisks);
}

Expand Down

0 comments on commit db33a56

Please sign in to comment.