Skip to content

Commit

Permalink
fix: accept brackets on the start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Oct 25, 2023
1 parent ebd4c37 commit 29980a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/crowdin/cli/properties/helper/FileMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class FileMatcher implements PathMatcher {
pattern = pattern.replace(Utils.PATH_SEPARATOR_REGEX + Utils.PATH_SEPARATOR_REGEX, Utils.PATH_SEPARATOR_REGEX);
}
}
pattern = pattern.replaceAll("\\\\\\\\\\[", "PLACEHOLDER_OPEN");
pattern = pattern.replaceAll("\\\\]", "PLACEHOLDER_CLOSE");

pattern = pattern.replaceAll("\\\\+", Utils.PATH_SEPARATOR_REGEX + Utils.PATH_SEPARATOR_REGEX);

pattern = pattern.replaceAll("PLACEHOLDER_OPEN", "\\\\\\\\\\\\[");
pattern = pattern.replaceAll("PLACEHOLDER_CLOSE", "\\\\]");

pattern = pattern.replaceAll("/+", "/");
pattern = pattern.replaceAll("\\{\\{+", "\\\\{\\\\{");
pattern = pattern.replaceAll("}}+", "\\\\}\\\\}");
pattern = pattern.replaceAll("\\[+", "\\\\[");
pattern = pattern.replaceAll("]+", "\\\\]");


// We *could* implement exactly what's documented. The idea would be to implement something like
// Java's Globs.toRegexPattern but supporting only the documented syntax. Instead, we will use
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,12 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) {
prefix = prefix.length() > 1 && file.getPath().contains(prefix) ? StringUtils.substringBefore(fileParent, Utils.noSepAtStart(prefix)) : "";
String doubleAsterisks =
StringUtils.removeStart(Utils.noSepAtStart(StringUtils.removeStart(fileParent, prefix)), Utils.noSepAtEnd(Utils.noSepAtStart(StringUtils.substringBefore(toFormat, "**"))));
doubleAsterisks = doubleAsterisks.replaceAll("\\[", "\\\\\\[");
doubleAsterisks = doubleAsterisks.replaceAll("]", "\\\\\\]");
toFormat = toFormat.replace("**", doubleAsterisks);
}

toFormat = toFormat.replaceAll("[\\\\/]+", Utils.PATH_SEPARATOR_REGEX);
toFormat = toFormat.replaceAll("[\\\\/]+(?!\\[)", Utils.PATH_SEPARATOR_REGEX);
return StringUtils.removeStart(toFormat, Utils.PATH_SEPARATOR);
}

Expand Down

0 comments on commit 29980a7

Please sign in to comment.