]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
pathmatch: Anchors within pattern not special 2924/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Mar 2026 10:17:02 +0000 (11:17 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Mar 2026 13:31:03 +0000 (14:31 +0100)
The anchor characters ^ and $ have only special meanings if they are
located at the beginning (^) or at the end ($) of the pattern. And even
then they are supposed to be only special if flags are set.

If they are located within the pattern itself, they are regular
characters regardless of flags.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_pathmatch.c
libarchive/test/test_archive_pathmatch.c

index 19e0889ffe553aad10b044f58af51272298651fb..db0d2b791adf87e32204084d3f7ae021ab146393 100644 (file)
@@ -202,7 +202,7 @@ pm(const char *p, const char *s, int flags)
                        if (*p == '\0')
                                return (1);
                        while (*s) {
-                               if (archive_pathmatch(p, s, flags))
+                               if (pm(p, s, flags))
                                        return (1);
                                ++s;
                        }
@@ -307,7 +307,7 @@ pm_w(const wchar_t *p, const wchar_t *s, int flags)
                        if (*p == L'\0')
                                return (1);
                        while (*s) {
-                               if (archive_pathmatch_w(p, s, flags))
+                               if (pm_w(p, s, flags))
                                        return (1);
                                ++s;
                        }
index 3696d38fcf19e56fdf074ad3eef8a8034c595d8c..3b212aca9d94225e909a3f767fe1d133a12758cd 100644 (file)
@@ -285,4 +285,22 @@ DEFINE_TEST(test_archive_pathmatch)
            archive_pathmatch("a/b/c$", "a/b/c/d", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
        assertEqualInt(1,
            archive_pathmatch("b/c/d$", "a/b/c/d", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+
+       /* Anchor characters within pattern not special. */
+       assertEqualInt(0,
+           archive_pathmatch("*^*", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(1,
+           archive_pathmatch("*^*", "a^b", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(0,
+           archive_pathmatch("*$*", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(1,
+           archive_pathmatch("*$*", "a$b", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(0,
+           archive_pathmatch("a*/^b/c", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(1,
+           archive_pathmatch("a*/^b/c", "a/^b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(0,
+           archive_pathmatch("a*/b$/c", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
+       assertEqualInt(1,
+           archive_pathmatch("a*/b$/c", "a/b$/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END));
 }