From e3c20eb27e7c33cf11c2a2c2821483c0a5acc9d3 Mon Sep 17 00:00:00 2001 From: yzerk Date: Wed, 10 May 2023 16:09:52 +0300 Subject: [PATCH] fix: support double curly braces (#572) --- .../crowdin/cli/properties/helper/FileMatcher.java | 2 ++ .../crowdin/cli/properties/helper/FileHelperTest.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/crowdin/cli/properties/helper/FileMatcher.java b/src/main/java/com/crowdin/cli/properties/helper/FileMatcher.java index d19140abc..1490ad279 100644 --- a/src/main/java/com/crowdin/cli/properties/helper/FileMatcher.java +++ b/src/main/java/com/crowdin/cli/properties/helper/FileMatcher.java @@ -26,6 +26,8 @@ class FileMatcher implements PathMatcher { } pattern = pattern.replaceAll("\\\\+", Utils.PATH_SEPARATOR_REGEX + Utils.PATH_SEPARATOR_REGEX); 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 diff --git a/src/test/java/com/crowdin/cli/properties/helper/FileHelperTest.java b/src/test/java/com/crowdin/cli/properties/helper/FileHelperTest.java index adbfaef32..844a3b149 100644 --- a/src/test/java/com/crowdin/cli/properties/helper/FileHelperTest.java +++ b/src/test/java/com/crowdin/cli/properties/helper/FileHelperTest.java @@ -78,6 +78,17 @@ public void testNpe() { "FileHelper should throw NPE in filterOutIgnoredFiles"); } + @Test + public void testFilterSourcesWithSpecialSymbols() { + List sources = new ArrayList<>(); + sources.add(new File("/files/folder/sub/1.xml")); + sources.add(new File("/files/{{cookiecutter.module_name}}")); + sources.add(new File("/files/{{cookiecutter.module_name}}/1.xml")); + FileHelper fileHelper = new FileHelper(project.getBasePath()); + List actualResult = fileHelper.filterOutIgnoredFiles(sources, Arrays.asList(".*")); + assertEquals(sources, actualResult); + } + @Test public void testGetFiles_WrongBasePath() { FileHelper fileHelper = new FileHelper(project.getBasePath() + "non_existent_folder");