rugged 1.9.4 → 1.9.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +1 -1
- data/vendor/libgit2/COPYING +83 -11
- data/vendor/libgit2/cmake/SelectRegex.cmake +8 -3
- data/vendor/libgit2/deps/pcre2/CMakeLists.txt +110 -0
- data/vendor/libgit2/deps/pcre2/LICENCE.md +104 -0
- data/vendor/libgit2/deps/pcre2/config.h.in +54 -0
- data/vendor/libgit2/deps/pcre2/pcre2.h +1079 -0
- data/vendor/libgit2/deps/pcre2/pcre2_auto_possess.c +1416 -0
- data/vendor/libgit2/deps/{pcre/pcre_chartables.c → pcre2/pcre2_chartables.c} +41 -47
- data/vendor/libgit2/deps/{pcre/pcre_ord2utf8.c → pcre2/pcre2_chkdint.c} +36 -36
- data/vendor/libgit2/deps/pcre2/pcre2_compile.c +11345 -0
- data/vendor/libgit2/deps/pcre2/pcre2_compile.h +356 -0
- data/vendor/libgit2/deps/pcre2/pcre2_compile_cgroup.c +632 -0
- data/vendor/libgit2/deps/pcre2/pcre2_compile_class.c +2777 -0
- data/vendor/libgit2/deps/pcre2/pcre2_config.c +250 -0
- data/vendor/libgit2/deps/pcre2/pcre2_context.c +557 -0
- data/vendor/libgit2/deps/pcre2/pcre2_convert.c +1263 -0
- data/vendor/libgit2/deps/{pcre/pcre_dfa_exec.c → pcre2/pcre2_dfa_match.c} +1402 -943
- data/vendor/libgit2/deps/pcre2/pcre2_error.c +384 -0
- data/vendor/libgit2/deps/pcre2/pcre2_extuni.c +159 -0
- data/vendor/libgit2/deps/pcre2/pcre2_find_bracket.c +217 -0
- data/vendor/libgit2/deps/pcre2/pcre2_fuzzsupport.c +844 -0
- data/vendor/libgit2/deps/pcre2/pcre2_internal.h +2353 -0
- data/vendor/libgit2/deps/pcre2/pcre2_intmodedep.h +1044 -0
- data/vendor/libgit2/deps/pcre2/pcre2_maketables.c +177 -0
- data/vendor/libgit2/deps/pcre2/pcre2_match.c +8244 -0
- data/vendor/libgit2/deps/pcre2/pcre2_match_data.c +184 -0
- data/vendor/libgit2/deps/pcre2/pcre2_match_next.c +171 -0
- data/vendor/libgit2/deps/{pcre/pcre_newline.c → pcre2/pcre2_newline.c} +92 -63
- data/vendor/libgit2/deps/{pcre/pcre_refcount.c → pcre2/pcre2_ord2utf.c} +64 -38
- data/vendor/libgit2/deps/pcre2/pcre2_pattern_info.c +430 -0
- data/vendor/libgit2/deps/pcre2/pcre2_printint_inc.h +1098 -0
- data/vendor/libgit2/deps/pcre2/pcre2_script_run.c +344 -0
- data/vendor/libgit2/deps/pcre2/pcre2_serialize.c +284 -0
- data/vendor/libgit2/deps/pcre2/pcre2_string_utils.c +199 -0
- data/vendor/libgit2/deps/pcre2/pcre2_study.c +2087 -0
- data/vendor/libgit2/deps/pcre2/pcre2_substitute.c +1761 -0
- data/vendor/libgit2/deps/pcre2/pcre2_substring.c +553 -0
- data/vendor/libgit2/deps/pcre2/pcre2_tables.c +310 -0
- data/vendor/libgit2/deps/pcre2/pcre2_ucd.c +5805 -0
- data/vendor/libgit2/deps/pcre2/pcre2_ucp.h +408 -0
- data/vendor/libgit2/deps/pcre2/pcre2_ucptables_inc.h +1596 -0
- data/vendor/libgit2/deps/pcre2/pcre2_util.h +179 -0
- data/vendor/libgit2/deps/pcre2/pcre2_valid_utf.c +397 -0
- data/vendor/libgit2/deps/pcre2/pcre2_xclass.c +547 -0
- data/vendor/libgit2/include/git2/common.h +13 -1
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/libgit2/blame.c +6 -0
- data/vendor/libgit2/src/libgit2/delta.c +8 -0
- data/vendor/libgit2/src/libgit2/indexer.c +3 -2
- data/vendor/libgit2/src/libgit2/settings.c +9 -0
- data/vendor/libgit2/src/libgit2/streams/openssl.c +4 -1
- data/vendor/libgit2/src/libgit2/submodule.c +77 -12
- data/vendor/libgit2/src/libgit2/transports/http.c +4 -4
- data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +2 -1
- data/vendor/libgit2/src/util/fs_path.h +10 -10
- data/vendor/libgit2/src/util/regexp.c +27 -12
- data/vendor/libgit2/src/util/regexp.h +7 -2
- metadata +44 -37
- data/vendor/libgit2/deps/pcre/CMakeLists.txt +0 -140
- data/vendor/libgit2/deps/pcre/COPYING +0 -5
- data/vendor/libgit2/deps/pcre/LICENCE +0 -93
- data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +0 -22
- data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +0 -17
- data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +0 -58
- data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +0 -29
- data/vendor/libgit2/deps/pcre/config.h.in +0 -57
- data/vendor/libgit2/deps/pcre/pcre.h +0 -641
- data/vendor/libgit2/deps/pcre/pcre_byte_order.c +0 -319
- data/vendor/libgit2/deps/pcre/pcre_compile.c +0 -9815
- data/vendor/libgit2/deps/pcre/pcre_config.c +0 -190
- data/vendor/libgit2/deps/pcre/pcre_exec.c +0 -7173
- data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +0 -245
- data/vendor/libgit2/deps/pcre/pcre_get.c +0 -669
- data/vendor/libgit2/deps/pcre/pcre_globals.c +0 -86
- data/vendor/libgit2/deps/pcre/pcre_internal.h +0 -2787
- data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +0 -11913
- data/vendor/libgit2/deps/pcre/pcre_maketables.c +0 -156
- data/vendor/libgit2/deps/pcre/pcre_printint.c +0 -834
- data/vendor/libgit2/deps/pcre/pcre_string_utils.c +0 -211
- data/vendor/libgit2/deps/pcre/pcre_study.c +0 -1686
- data/vendor/libgit2/deps/pcre/pcre_tables.c +0 -727
- data/vendor/libgit2/deps/pcre/pcre_ucd.c +0 -3644
- data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +0 -301
- data/vendor/libgit2/deps/pcre/pcre_version.c +0 -98
- data/vendor/libgit2/deps/pcre/pcre_xclass.c +0 -268
- data/vendor/libgit2/deps/pcre/pcreposix.c +0 -420
- data/vendor/libgit2/deps/pcre/pcreposix.h +0 -117
- data/vendor/libgit2/deps/pcre/ucp.h +0 -224
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*************************************************
|
|
2
|
+
* Perl-Compatible Regular Expressions *
|
|
3
|
+
*************************************************/
|
|
4
|
+
|
|
5
|
+
/* PCRE2 is a library of functions to support regular expressions whose syntax
|
|
6
|
+
and semantics are as close as possible to those of the Perl 5 language.
|
|
7
|
+
|
|
8
|
+
Written by Philip Hazel
|
|
9
|
+
Original API code Copyright (c) 1997-2012 University of Cambridge
|
|
10
|
+
New API code Copyright (c) 2016-2024 University of Cambridge
|
|
11
|
+
|
|
12
|
+
-----------------------------------------------------------------------------
|
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
documentation and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
* Neither the name of the University of Cambridge nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from
|
|
25
|
+
this software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
28
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
29
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
30
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
31
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
32
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
33
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
34
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
35
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
36
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
37
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
38
|
+
-----------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
#ifndef PCRE2_UTIL_H_IDEMPOTENT_GUARD
|
|
42
|
+
#define PCRE2_UTIL_H_IDEMPOTENT_GUARD
|
|
43
|
+
|
|
44
|
+
/* Assertion macros */
|
|
45
|
+
|
|
46
|
+
#ifdef PCRE2_DEBUG
|
|
47
|
+
|
|
48
|
+
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
|
|
49
|
+
#include <assert.h>
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions
|
|
53
|
+
that the code below doesn't support. It is a NOP for non debug builds
|
|
54
|
+
but in debug builds will print information about the location of the
|
|
55
|
+
code where it triggered and crash.
|
|
56
|
+
|
|
57
|
+
It is meant to work like assert(), and therefore the expression used
|
|
58
|
+
should indicate what the expected state is, and shouldn't have any
|
|
59
|
+
side-effects. */
|
|
60
|
+
|
|
61
|
+
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
|
|
62
|
+
#define PCRE2_ASSERT(x) assert(x)
|
|
63
|
+
#else
|
|
64
|
+
#define PCRE2_ASSERT(x) do \
|
|
65
|
+
{ \
|
|
66
|
+
if (!(x)) \
|
|
67
|
+
{ \
|
|
68
|
+
fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); \
|
|
69
|
+
abort(); \
|
|
70
|
+
} \
|
|
71
|
+
} while(0)
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
/* LCOV_EXCL_START */
|
|
75
|
+
|
|
76
|
+
/* PCRE2_UNREACHABLE() can be used to mark locations on the code that
|
|
77
|
+
shouldn't be reached. In non debug builds is defined as a hint for
|
|
78
|
+
the compiler to eliminate any code after it, so it is useful also for
|
|
79
|
+
performance reasons, but should be used with care because if it is
|
|
80
|
+
ever reached will trigger Undefined Behaviour and if you are lucky a
|
|
81
|
+
crash. In debug builds it will report the location where it was triggered
|
|
82
|
+
and crash. One important point to consider when using this macro, is
|
|
83
|
+
that it is only implemented for a few compilers, and therefore can't
|
|
84
|
+
be relied on to always be active either, so if it is followed by some
|
|
85
|
+
code it is important to make sure that the whole thing is safe to
|
|
86
|
+
use even if the macro is not there (ex: make sure there is a `break`
|
|
87
|
+
after it if used at the end of a `case`) and to test your code also
|
|
88
|
+
with a configuration where the macro will be a NOP. */
|
|
89
|
+
|
|
90
|
+
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
|
|
91
|
+
#define PCRE2_UNREACHABLE() \
|
|
92
|
+
assert(((void)"Execution reached unexpected point", 0))
|
|
93
|
+
#else
|
|
94
|
+
#define PCRE2_UNREACHABLE() do \
|
|
95
|
+
{ \
|
|
96
|
+
fprintf(stderr, "Execution reached unexpected point at " __FILE__ \
|
|
97
|
+
":%d\n", __LINE__); \
|
|
98
|
+
abort(); \
|
|
99
|
+
} while(0)
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous
|
|
103
|
+
macro. It is meant to be used in places where the code is handling
|
|
104
|
+
an error situation in code that shouldn't be reached, but that has
|
|
105
|
+
some sort of fallback code to normally handle the error. When in
|
|
106
|
+
doubt you should use this instead of the previous macro. Like in
|
|
107
|
+
the previous case, it is a good idea to document as much as possible
|
|
108
|
+
the reason and the actions that should be taken if it ever triggers. */
|
|
109
|
+
|
|
110
|
+
#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE()
|
|
111
|
+
|
|
112
|
+
/* LCOV_EXCL_STOP */
|
|
113
|
+
|
|
114
|
+
#endif /* PCRE2_DEBUG */
|
|
115
|
+
|
|
116
|
+
#ifndef PCRE2_ASSERT
|
|
117
|
+
#define PCRE2_ASSERT(x) do {} while(0)
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
/* LCOV_EXCL_START */
|
|
121
|
+
|
|
122
|
+
#ifndef PCRE2_DEBUG_UNREACHABLE
|
|
123
|
+
#define PCRE2_DEBUG_UNREACHABLE() do {} while(0)
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
#ifndef PCRE2_UNREACHABLE
|
|
127
|
+
#ifdef HAVE_BUILTIN_UNREACHABLE
|
|
128
|
+
#define PCRE2_UNREACHABLE() __builtin_unreachable()
|
|
129
|
+
#elif defined(HAVE_BUILTIN_ASSUME)
|
|
130
|
+
#define PCRE2_UNREACHABLE() __assume(0)
|
|
131
|
+
#else
|
|
132
|
+
#define PCRE2_UNREACHABLE() do {} while(0)
|
|
133
|
+
#endif
|
|
134
|
+
#endif /* !PCRE2_UNREACHABLE */
|
|
135
|
+
|
|
136
|
+
/* LCOV_EXCL_STOP */
|
|
137
|
+
|
|
138
|
+
/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings.
|
|
139
|
+
Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes
|
|
140
|
+
and also specially-formatted comments.
|
|
141
|
+
|
|
142
|
+
This macro should be used with no following semicolon, and ideally with a comment: */
|
|
143
|
+
|
|
144
|
+
/* PCRE2_FALLTHROUGH */ /* Fall through */
|
|
145
|
+
|
|
146
|
+
#ifndef PCRE2_FALLTHROUGH
|
|
147
|
+
|
|
148
|
+
#if defined(__cplusplus) && __cplusplus >= 202002L && \
|
|
149
|
+
defined(__has_cpp_attribute)
|
|
150
|
+
/* Standards-compatible C++ variant. */
|
|
151
|
+
#if __has_cpp_attribute(fallthrough)
|
|
152
|
+
#define PCRE2_FALLTHROUGH [[fallthrough]];
|
|
153
|
+
#endif
|
|
154
|
+
#elif !defined(__cplusplus) && \
|
|
155
|
+
defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \
|
|
156
|
+
defined(__has_c_attribute)
|
|
157
|
+
/* Standards-compatible C variant. */
|
|
158
|
+
#if __has_c_attribute(fallthrough)
|
|
159
|
+
#define PCRE2_FALLTHROUGH [[fallthrough]];
|
|
160
|
+
#endif
|
|
161
|
+
#elif ((defined(__clang__) && __clang_major__ >= 10) || \
|
|
162
|
+
(defined(__GNUC__) && __GNUC__ >= 7)) && \
|
|
163
|
+
defined(__has_attribute)
|
|
164
|
+
/* Clang and GCC syntax. Rule out old versions because apparently Clang at
|
|
165
|
+
least has a broken implementation of __has_attribute. */
|
|
166
|
+
#if __has_attribute(fallthrough)
|
|
167
|
+
#define PCRE2_FALLTHROUGH __attribute__((fallthrough));
|
|
168
|
+
#endif
|
|
169
|
+
#endif
|
|
170
|
+
|
|
171
|
+
#endif /* !PCRE2_FALLTHROUGH */
|
|
172
|
+
|
|
173
|
+
#ifndef PCRE2_FALLTHROUGH
|
|
174
|
+
#define PCRE2_FALLTHROUGH
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
#endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */
|
|
178
|
+
|
|
179
|
+
/* End of pcre2_util.h */
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/*************************************************
|
|
2
|
+
* Perl-Compatible Regular Expressions *
|
|
3
|
+
*************************************************/
|
|
4
|
+
|
|
5
|
+
/* PCRE is a library of functions to support regular expressions whose syntax
|
|
6
|
+
and semantics are as close as possible to those of the Perl 5 language.
|
|
7
|
+
|
|
8
|
+
Written by Philip Hazel
|
|
9
|
+
Original API code Copyright (c) 1997-2012 University of Cambridge
|
|
10
|
+
New API code Copyright (c) 2016-2020 University of Cambridge
|
|
11
|
+
|
|
12
|
+
-----------------------------------------------------------------------------
|
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
documentation and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
* Neither the name of the University of Cambridge nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from
|
|
25
|
+
this software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
28
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
29
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
30
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
31
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
32
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
33
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
34
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
35
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
36
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
37
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
38
|
+
-----------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/* This module contains an internal function for validating UTF character
|
|
43
|
+
strings. This file is also #included by the pcre2test program, which uses
|
|
44
|
+
macros to change names from _pcre2_xxx to xxxx, thereby avoiding name clashes
|
|
45
|
+
with the library. In this case, PCRE2_PCRE2TEST is defined. */
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#ifndef PCRE2_PCRE2TEST /* We're compiling the library */
|
|
49
|
+
#include "pcre2_internal.h"
|
|
50
|
+
#endif /* PCRE2_PCRE2TEST */
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
#ifndef SUPPORT_UNICODE
|
|
55
|
+
/*************************************************
|
|
56
|
+
* Dummy function when Unicode is not supported *
|
|
57
|
+
*************************************************/
|
|
58
|
+
|
|
59
|
+
/* This function should never be called when Unicode is not supported. */
|
|
60
|
+
|
|
61
|
+
int
|
|
62
|
+
PRIV(valid_utf)(PCRE2_SPTR string, PCRE2_SIZE length, PCRE2_SIZE *erroroffset)
|
|
63
|
+
{
|
|
64
|
+
(void)string;
|
|
65
|
+
(void)length;
|
|
66
|
+
(void)erroroffset;
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
#else /* UTF is supported */
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/*************************************************
|
|
74
|
+
* Validate a UTF string *
|
|
75
|
+
*************************************************/
|
|
76
|
+
|
|
77
|
+
/* This function is called (optionally) at the start of compile or match, to
|
|
78
|
+
check that a supposed UTF string is actually valid. The early check means
|
|
79
|
+
that subsequent code can assume it is dealing with a valid string. The check
|
|
80
|
+
can be turned off for maximum performance, but the consequences of supplying an
|
|
81
|
+
invalid string are then undefined.
|
|
82
|
+
|
|
83
|
+
Arguments:
|
|
84
|
+
string points to the string
|
|
85
|
+
length length of string
|
|
86
|
+
errp pointer to an error position offset variable
|
|
87
|
+
|
|
88
|
+
Returns: == 0 if the string is a valid UTF string
|
|
89
|
+
!= 0 otherwise, setting the offset of the bad character
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
int
|
|
93
|
+
PRIV(valid_utf)(PCRE2_SPTR string, PCRE2_SIZE length, PCRE2_SIZE *erroroffset)
|
|
94
|
+
{
|
|
95
|
+
PCRE2_SPTR p;
|
|
96
|
+
uint32_t c;
|
|
97
|
+
|
|
98
|
+
/* ----------------- Check a UTF-8 string ----------------- */
|
|
99
|
+
|
|
100
|
+
#if PCRE2_CODE_UNIT_WIDTH == 8
|
|
101
|
+
|
|
102
|
+
/* Originally, this function checked according to RFC 2279, allowing for values
|
|
103
|
+
in the range 0 to 0x7fffffff, up to 6 bytes long, but ensuring that they were
|
|
104
|
+
in the canonical format. Once somebody had pointed out RFC 3629 to me (it
|
|
105
|
+
obsoletes 2279), additional restrictions were applied. The values are now
|
|
106
|
+
limited to be between 0 and 0x0010ffff, no more than 4 bytes long, and the
|
|
107
|
+
subrange 0xd000 to 0xdfff is excluded. However, the format of 5-byte and 6-byte
|
|
108
|
+
characters is still checked. Error returns are as follows:
|
|
109
|
+
|
|
110
|
+
PCRE2_ERROR_UTF8_ERR1 Missing 1 byte at the end of the string
|
|
111
|
+
PCRE2_ERROR_UTF8_ERR2 Missing 2 bytes at the end of the string
|
|
112
|
+
PCRE2_ERROR_UTF8_ERR3 Missing 3 bytes at the end of the string
|
|
113
|
+
PCRE2_ERROR_UTF8_ERR4 Missing 4 bytes at the end of the string
|
|
114
|
+
PCRE2_ERROR_UTF8_ERR5 Missing 5 bytes at the end of the string
|
|
115
|
+
PCRE2_ERROR_UTF8_ERR6 2nd-byte's two top bits are not 0x80
|
|
116
|
+
PCRE2_ERROR_UTF8_ERR7 3rd-byte's two top bits are not 0x80
|
|
117
|
+
PCRE2_ERROR_UTF8_ERR8 4th-byte's two top bits are not 0x80
|
|
118
|
+
PCRE2_ERROR_UTF8_ERR9 5th-byte's two top bits are not 0x80
|
|
119
|
+
PCRE2_ERROR_UTF8_ERR10 6th-byte's two top bits are not 0x80
|
|
120
|
+
PCRE2_ERROR_UTF8_ERR11 5-byte character is not permitted by RFC 3629
|
|
121
|
+
PCRE2_ERROR_UTF8_ERR12 6-byte character is not permitted by RFC 3629
|
|
122
|
+
PCRE2_ERROR_UTF8_ERR13 4-byte character with value > 0x10ffff is not permitted
|
|
123
|
+
PCRE2_ERROR_UTF8_ERR14 3-byte character with value 0xd800-0xdfff is not permitted
|
|
124
|
+
PCRE2_ERROR_UTF8_ERR15 Overlong 2-byte sequence
|
|
125
|
+
PCRE2_ERROR_UTF8_ERR16 Overlong 3-byte sequence
|
|
126
|
+
PCRE2_ERROR_UTF8_ERR17 Overlong 4-byte sequence
|
|
127
|
+
PCRE2_ERROR_UTF8_ERR18 Overlong 5-byte sequence (won't ever occur)
|
|
128
|
+
PCRE2_ERROR_UTF8_ERR19 Overlong 6-byte sequence (won't ever occur)
|
|
129
|
+
PCRE2_ERROR_UTF8_ERR20 Isolated 0x80 byte (not within UTF-8 character)
|
|
130
|
+
PCRE2_ERROR_UTF8_ERR21 Byte with the illegal value 0xfe or 0xff
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
for (p = string; length > 0; p++)
|
|
134
|
+
{
|
|
135
|
+
uint32_t ab, d;
|
|
136
|
+
|
|
137
|
+
c = *p;
|
|
138
|
+
length--;
|
|
139
|
+
|
|
140
|
+
if (c < 128) continue; /* ASCII character */
|
|
141
|
+
|
|
142
|
+
if (c < 0xc0) /* Isolated 10xx xxxx byte */
|
|
143
|
+
{
|
|
144
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
145
|
+
return PCRE2_ERROR_UTF8_ERR20;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (c >= 0xfe) /* Invalid 0xfe or 0xff bytes */
|
|
149
|
+
{
|
|
150
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
151
|
+
return PCRE2_ERROR_UTF8_ERR21;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
ab = PRIV(utf8_table4)[c & 0x3f]; /* Number of additional bytes (1-5) */
|
|
155
|
+
if (length < ab) /* Missing bytes */
|
|
156
|
+
{
|
|
157
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
158
|
+
switch(ab - length)
|
|
159
|
+
{
|
|
160
|
+
case 1: return PCRE2_ERROR_UTF8_ERR1;
|
|
161
|
+
case 2: return PCRE2_ERROR_UTF8_ERR2;
|
|
162
|
+
case 3: return PCRE2_ERROR_UTF8_ERR3;
|
|
163
|
+
case 4: return PCRE2_ERROR_UTF8_ERR4;
|
|
164
|
+
case 5: return PCRE2_ERROR_UTF8_ERR5;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
length -= ab; /* Length remaining */
|
|
168
|
+
|
|
169
|
+
/* Check top bits in the second byte */
|
|
170
|
+
|
|
171
|
+
if (((d = *(++p)) & 0xc0) != 0x80)
|
|
172
|
+
{
|
|
173
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 1;
|
|
174
|
+
return PCRE2_ERROR_UTF8_ERR6;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* For each length, check that the remaining bytes start with the 0x80 bit
|
|
178
|
+
set and not the 0x40 bit. Then check for an overlong sequence, and for the
|
|
179
|
+
excluded range 0xd800 to 0xdfff. */
|
|
180
|
+
|
|
181
|
+
switch (ab)
|
|
182
|
+
{
|
|
183
|
+
/* 2-byte character. No further bytes to check for 0x80. Check first byte
|
|
184
|
+
for for xx00 000x (overlong sequence). */
|
|
185
|
+
|
|
186
|
+
case 1: if ((c & 0x3e) == 0)
|
|
187
|
+
{
|
|
188
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 1;
|
|
189
|
+
return PCRE2_ERROR_UTF8_ERR15;
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
|
|
193
|
+
/* 3-byte character. Check third byte for 0x80. Then check first 2 bytes
|
|
194
|
+
for 1110 0000, xx0x xxxx (overlong sequence) or
|
|
195
|
+
1110 1101, 1010 xxxx (0xd800 - 0xdfff) */
|
|
196
|
+
|
|
197
|
+
case 2:
|
|
198
|
+
if ((*(++p) & 0xc0) != 0x80) /* Third byte */
|
|
199
|
+
{
|
|
200
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
201
|
+
return PCRE2_ERROR_UTF8_ERR7;
|
|
202
|
+
}
|
|
203
|
+
if (c == 0xe0 && (d & 0x20) == 0)
|
|
204
|
+
{
|
|
205
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
206
|
+
return PCRE2_ERROR_UTF8_ERR16;
|
|
207
|
+
}
|
|
208
|
+
if (c == 0xed && d >= 0xa0)
|
|
209
|
+
{
|
|
210
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
211
|
+
return PCRE2_ERROR_UTF8_ERR14;
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
/* 4-byte character. Check 3rd and 4th bytes for 0x80. Then check first 2
|
|
216
|
+
bytes for for 1111 0000, xx00 xxxx (overlong sequence), then check for a
|
|
217
|
+
character greater than 0x0010ffff (f4 8f bf bf) */
|
|
218
|
+
|
|
219
|
+
case 3:
|
|
220
|
+
if ((*(++p) & 0xc0) != 0x80) /* Third byte */
|
|
221
|
+
{
|
|
222
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
223
|
+
return PCRE2_ERROR_UTF8_ERR7;
|
|
224
|
+
}
|
|
225
|
+
if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */
|
|
226
|
+
{
|
|
227
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 3;
|
|
228
|
+
return PCRE2_ERROR_UTF8_ERR8;
|
|
229
|
+
}
|
|
230
|
+
if (c == 0xf0 && (d & 0x30) == 0)
|
|
231
|
+
{
|
|
232
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 3;
|
|
233
|
+
return PCRE2_ERROR_UTF8_ERR17;
|
|
234
|
+
}
|
|
235
|
+
if (c > 0xf4 || (c == 0xf4 && d > 0x8f))
|
|
236
|
+
{
|
|
237
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 3;
|
|
238
|
+
return PCRE2_ERROR_UTF8_ERR13;
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
/* 5-byte and 6-byte characters are not allowed by RFC 3629, and will be
|
|
243
|
+
rejected by the length test below. However, we do the appropriate tests
|
|
244
|
+
here so that overlong sequences get diagnosed, and also in case there is
|
|
245
|
+
ever an option for handling these larger code points. */
|
|
246
|
+
|
|
247
|
+
/* 5-byte character. Check 3rd, 4th, and 5th bytes for 0x80. Then check for
|
|
248
|
+
1111 1000, xx00 0xxx */
|
|
249
|
+
|
|
250
|
+
case 4:
|
|
251
|
+
if ((*(++p) & 0xc0) != 0x80) /* Third byte */
|
|
252
|
+
{
|
|
253
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
254
|
+
return PCRE2_ERROR_UTF8_ERR7;
|
|
255
|
+
}
|
|
256
|
+
if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */
|
|
257
|
+
{
|
|
258
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 3;
|
|
259
|
+
return PCRE2_ERROR_UTF8_ERR8;
|
|
260
|
+
}
|
|
261
|
+
if ((*(++p) & 0xc0) != 0x80) /* Fifth byte */
|
|
262
|
+
{
|
|
263
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 4;
|
|
264
|
+
return PCRE2_ERROR_UTF8_ERR9;
|
|
265
|
+
}
|
|
266
|
+
if (c == 0xf8 && (d & 0x38) == 0)
|
|
267
|
+
{
|
|
268
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 4;
|
|
269
|
+
return PCRE2_ERROR_UTF8_ERR18;
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
|
|
273
|
+
/* 6-byte character. Check 3rd-6th bytes for 0x80. Then check for
|
|
274
|
+
1111 1100, xx00 00xx. */
|
|
275
|
+
|
|
276
|
+
case 5:
|
|
277
|
+
if ((*(++p) & 0xc0) != 0x80) /* Third byte */
|
|
278
|
+
{
|
|
279
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 2;
|
|
280
|
+
return PCRE2_ERROR_UTF8_ERR7;
|
|
281
|
+
}
|
|
282
|
+
if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */
|
|
283
|
+
{
|
|
284
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 3;
|
|
285
|
+
return PCRE2_ERROR_UTF8_ERR8;
|
|
286
|
+
}
|
|
287
|
+
if ((*(++p) & 0xc0) != 0x80) /* Fifth byte */
|
|
288
|
+
{
|
|
289
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 4;
|
|
290
|
+
return PCRE2_ERROR_UTF8_ERR9;
|
|
291
|
+
}
|
|
292
|
+
if ((*(++p) & 0xc0) != 0x80) /* Sixth byte */
|
|
293
|
+
{
|
|
294
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 5;
|
|
295
|
+
return PCRE2_ERROR_UTF8_ERR10;
|
|
296
|
+
}
|
|
297
|
+
if (c == 0xfc && (d & 0x3c) == 0)
|
|
298
|
+
{
|
|
299
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 5;
|
|
300
|
+
return PCRE2_ERROR_UTF8_ERR19;
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/* Character is valid under RFC 2279, but 4-byte and 5-byte characters are
|
|
306
|
+
excluded by RFC 3629. The pointer p is currently at the last byte of the
|
|
307
|
+
character. */
|
|
308
|
+
|
|
309
|
+
if (ab > 3)
|
|
310
|
+
{
|
|
311
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - ab;
|
|
312
|
+
return (ab == 4)? PCRE2_ERROR_UTF8_ERR11 : PCRE2_ERROR_UTF8_ERR12;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return 0;
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
/* ----------------- Check a UTF-16 string ----------------- */
|
|
319
|
+
|
|
320
|
+
#elif PCRE2_CODE_UNIT_WIDTH == 16
|
|
321
|
+
|
|
322
|
+
/* There's not so much work, nor so many errors, for UTF-16.
|
|
323
|
+
PCRE2_ERROR_UTF16_ERR1 Missing low surrogate at the end of the string
|
|
324
|
+
PCRE2_ERROR_UTF16_ERR2 Invalid low surrogate
|
|
325
|
+
PCRE2_ERROR_UTF16_ERR3 Isolated low surrogate
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
for (p = string; length > 0; p++)
|
|
329
|
+
{
|
|
330
|
+
c = *p;
|
|
331
|
+
length--;
|
|
332
|
+
|
|
333
|
+
if ((c & 0xf800) != 0xd800)
|
|
334
|
+
{
|
|
335
|
+
/* Normal UTF-16 code point. Neither high nor low surrogate. */
|
|
336
|
+
}
|
|
337
|
+
else if ((c & 0x0400) == 0)
|
|
338
|
+
{
|
|
339
|
+
/* High surrogate. Must be a followed by a low surrogate. */
|
|
340
|
+
if (length == 0)
|
|
341
|
+
{
|
|
342
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
343
|
+
return PCRE2_ERROR_UTF16_ERR1;
|
|
344
|
+
}
|
|
345
|
+
p++;
|
|
346
|
+
length--;
|
|
347
|
+
if ((*p & 0xfc00) != 0xdc00)
|
|
348
|
+
{
|
|
349
|
+
*erroroffset = (PCRE2_SIZE)(p - string) - 1;
|
|
350
|
+
return PCRE2_ERROR_UTF16_ERR2;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else
|
|
354
|
+
{
|
|
355
|
+
/* Isolated low surrogate. Always an error. */
|
|
356
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
357
|
+
return PCRE2_ERROR_UTF16_ERR3;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return 0;
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
/* ----------------- Check a UTF-32 string ----------------- */
|
|
365
|
+
|
|
366
|
+
#else
|
|
367
|
+
|
|
368
|
+
/* There is very little to do for a UTF-32 string.
|
|
369
|
+
PCRE2_ERROR_UTF32_ERR1 Surrogate character
|
|
370
|
+
PCRE2_ERROR_UTF32_ERR2 Character > 0x10ffff
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
for (p = string; length > 0; length--, p++)
|
|
374
|
+
{
|
|
375
|
+
c = *p;
|
|
376
|
+
if ((c & 0xfffff800u) != 0xd800u)
|
|
377
|
+
{
|
|
378
|
+
/* Normal UTF-32 code point. Neither high nor low surrogate. */
|
|
379
|
+
if (c > 0x10ffffu)
|
|
380
|
+
{
|
|
381
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
382
|
+
return PCRE2_ERROR_UTF32_ERR2;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else
|
|
386
|
+
{
|
|
387
|
+
/* A surrogate */
|
|
388
|
+
*erroroffset = (PCRE2_SIZE)(p - string);
|
|
389
|
+
return PCRE2_ERROR_UTF32_ERR1;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return 0;
|
|
393
|
+
#endif /* CODE_UNIT_WIDTH */
|
|
394
|
+
}
|
|
395
|
+
#endif /* SUPPORT_UNICODE */
|
|
396
|
+
|
|
397
|
+
/* End of pcre2_valid_utf.c */
|