Skip to content

Commit

Permalink
Merge pull request #484 from crowdin/bug/292
Browse files Browse the repository at this point in the history
fixed regex to work correctly for Windows machines
  • Loading branch information
andrii-bodnar committed Oct 17, 2022
2 parents ed2c218 + bc1b294 commit ce059ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public static Stream<File> getFiles(String basePath, String sourcePattern, List<
public static List<String> filterProjectFiles(
List<String> filePaths, String sourcePattern, List<String> ignorePatterns, boolean preserveHierarchy, PlaceholderUtil placeholderUtil
) {
filePaths = filePaths.stream().map(Utils::unixPath).map(Utils::noSepAtStart).collect(Collectors.toList());
sourcePattern = Utils.noSepAtStart(Utils.unixPath(sourcePattern));
filePaths = filePaths.stream().map((Utils.isWindows() ? Utils::windowsPath : Utils::unixPath)).map(Utils::noSepAtStart).collect(Collectors.toList());
sourcePattern = Utils.noSepAtStart(Utils.isWindows() ? Utils.windowsPath(sourcePattern) : Utils.unixPath(sourcePattern));
ignorePatterns = (ignorePatterns != null)
? ignorePatterns.stream().map(Utils::unixPath).map(Utils::noSepAtStart).collect(Collectors.toList()) : Collections.emptyList();
? ignorePatterns.stream().map((Utils.isWindows() ? Utils::windowsPath : Utils::unixPath)).map(Utils::noSepAtStart).collect(Collectors.toList()) : Collections.emptyList();

Predicate<String> sourcePredicate;
Predicate<String> ignorePredicate;
if (preserveHierarchy) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public static String formatSourcePatternForRegex(String toFormat) {
if (Utils.isWindows()) {
toFormat = toFormat
.replace("**", ".+")
.replace("\\", "\\\\")
.replace(ASTERISK, "[^/]+");
} else {
toFormat = toFormat
Expand All @@ -247,7 +248,6 @@ public static String formatSourcePatternForRegex(String toFormat) {
.replace(ASTERISK, "[^/]+")
.replace(ESCAPE_ASTERISK_PLACEHOLDER, ESCAPE_ASTERISK);
}

toFormat = toFormat
.replace(ROUND_BRACKET_OPEN, ESCAPE_ROUND_BRACKET_OPEN)

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/crowdin/cli/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public static String unixPath(String path) {
return (path != null) ? path.replaceAll("[\\\\/]+", "/") : null;
}

public static String windowsPath(String path) {
return (path != null) ? path.replaceAll("[\\\\/]+", "\\\\") : null;
}

public static String normalizePath(String path) {
return (path != null) ? path.replaceAll("[\\\\/]+", Utils.PATH_SEPARATOR_REGEX) : null;
}
Expand Down

0 comments on commit ce059ff

Please sign in to comment.