From aea7b99ca7a65ed50196059e2ffa8e6365eceede Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 25 Nov 2024 10:52:47 +0200 Subject: [PATCH] Fix glob to regex conversation to properly handle **/*.suffix --- .../app-model/src/main/java/io/quarkus/util/GlobUtil.java | 7 ++++++- .../src/test/java/io/quarkus/util/GlobUtilTest.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/util/GlobUtil.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/util/GlobUtil.java index 84ce28d1a1ae71..e717aea3b5ee13 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/util/GlobUtil.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/util/GlobUtil.java @@ -75,8 +75,13 @@ private static int glob(String glob, int i, int length, String stopChars, String switch (current) { case '*': if (i < length && glob.charAt(i) == '*') { - result.append(".*"); i++; + if (i < length && glob.charAt(i) == '/') { + result.append("([^/]*/)*"); + i++; + } else { + result.append(".*"); + } } else { result.append("[^/]*"); } diff --git a/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/util/GlobUtilTest.java b/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/util/GlobUtilTest.java index 7ec0ebecdd9439..ac10345eb401a8 100644 --- a/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/util/GlobUtilTest.java +++ b/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/util/GlobUtilTest.java @@ -34,6 +34,8 @@ void doubleStar() { assertMatch("a**/b", Arrays.asList("a/b", "axy/b", "a/x/b"), Arrays.asList("a", "b", "a/bc", "bc/b")); assertMatch("a**b", Arrays.asList("ab", "axb", "axyb", "a/b", "a/x/b"), Arrays.asList("abc", "1ab")); assertMatch("a**b**/c", Arrays.asList("axbx/c", "axbx/c", "a/x/xbx/c", "axbx/xxx/c"), Arrays.asList("axbx/cc")); + assertMatch("**/*.txt", Arrays.asList("/test.txt", "test.txt", "/path/to/a.txt", "relative/path/to/a.txt"), + Arrays.asList("/test.py", "test.json", "/path/to/a.js", "relative/path/to/a.exe")); } @Test