Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed regex to work correctly for Windows machines #484

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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