summaryrefslogtreecommitdiffstats
path: root/pcre2.patch
blob: bdff4d5568b9e886fa6783d2252133b792c11c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From 8dc64d7f39ad64814d6b6be2058c8d3d7a7d7ebc Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Fri, 29 Nov 2024 15:58:32 +0100
Subject: [PATCH] switch from pcre to pcre2

---
 configure.ac                        |  3 ++-
 tests/test_spec_handlebars_parser.c |  1 -
 tests/utils.c                       | 32 ++++++++++++++---------------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index 45c3b3e..88307db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -377,7 +377,8 @@ AS_IF([test "x$with_mustache_spec" != "xno"], [
 # pcre
 AC_ARG_ENABLE([pcre], [AS_HELP_STRING([--disable-pcre], [disable support for pcre])], [])
 AS_IF([test "x$enable_pcre" != "xno"], [
-	PKG_CHECK_MODULES(PCRE, [libpcre], [enable_pcre=yes], [AC_MSG_WARN([libpcre not found])])
+	PKG_CHECK_MODULES(PCRE, [libpcre2-8], [enable_pcre=yes], [AC_MSG_WARN([libpcre2-8 not found])])
+	AC_DEFINE(PCRE2_CODE_UNIT_WIDTH, 8, [ ])
 ])
 AS_IF([test "x$enable_pcre" == "xyes"], [
 	AC_DEFINE([HANDLEBARS_HAVE_PCRE], [1], [Use PCRE])
diff --git a/tests/test_spec_handlebars_parser.c b/tests/test_spec_handlebars_parser.c
index 21dddba..5f506f3 100644
--- a/tests/test_spec_handlebars_parser.c
+++ b/tests/test_spec_handlebars_parser.c
@@ -22,7 +22,6 @@
 #include <errno.h>
 #include <check.h>
 #include <stdio.h>
-#include <pcre.h>
 #include <talloc.h>
 
 // json-c undeprecated json_object_object_get, but the version in xenial
diff --git a/tests/utils.c b/tests/utils.c
index 437a528..369e910 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -23,7 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <pcre.h>
+#include <pcre2.h>
 #include <talloc.h>
 
 #include <errno.h>
@@ -187,33 +187,33 @@ int scan_directory_callback(char * dirname, scan_directory_cb cb)
 
 int regex_compare(const char * regex, const char * string, char ** error)
 {
-    pcre * re;
-    const char * errmsg = NULL;
-    int erroffset;
-    int ovector[30];
+    pcre2_code *re;
+    int errorcode = 0;
+    PCRE2_UCHAR errmsg[128];
+    PCRE2_SIZE erroffset;
+    pcre2_match_data *ovector;
     int rc, ret;
 
-    re = pcre_compile(regex, 0, &errmsg, &erroffset, NULL);
+    re = pcre2_compile((PCRE2_SPTR)regex, PCRE2_ZERO_TERMINATED, 0, &errorcode, &erroffset, NULL);
 
-    if( !re ) {
-        *error = talloc_asprintf(NULL, "Regex '%s' compilation failed at offset %d: %s\n", regex, erroffset, errmsg);
+    if (!re) {
+        pcre2_get_error_message(errorcode, errmsg, sizeof(errmsg));
+        *error = talloc_asprintf(NULL, "Regex '%s' compilation failed at offset %ld: %s\n", regex, erroffset, errmsg);
         return 1;
-    } else if( errmsg ) {
-        *error = talloc_strdup(NULL, errmsg);
-        ret = 2;
-        goto error;
     }
 
-    rc = pcre_exec(re, NULL, string, (int) strlen(string), 0, 0, ovector, 30);
-    if( rc <= 0 ) {
+    ovector = pcre2_match_data_create_from_pattern(re, NULL);
+    rc = pcre2_match(re, (PCRE2_SPTR)string, (PCRE2_SIZE)strlen(string), 0, 0, ovector, NULL);
+    if (rc <= 0) {
         ret = 2;
         *error = talloc_asprintf(NULL, "Regex '%s' didn't match string '%s'", regex, string);
     } else {
         ret = 0;
     }
 
-error:
-    pcre_free(re);
+    pcre2_match_data_free(ovector);
+    pcre2_code_free(re);
+
     return ret;
 }