diff --git a/ChangeLog b/ChangeLog index 934f799..1a92b9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,8 @@ from pcre2grep. 9. Merged patch from @carenas (GitHub #53) fixing NULL checks in matching and substituting. +10. Add null_subject and null_replacement modifiers to pcre2test. + Version 10.39 29-October-2021 ----------------------------- diff --git a/doc/html/pcre2api.html b/doc/html/pcre2api.html index 44158f8..fab6e4a 100644 --- a/doc/html/pcre2api.html +++ b/doc/html/pcre2api.html @@ -3655,7 +3655,9 @@ default.

PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the -match_data argument is NULL. +match_data argument is NULL or if the subject or replacement +arguments are NULL. For backward compatibility reasons an exception is made for +the replacement argument if the rlength argument is also 0.

PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the diff --git a/doc/html/pcre2test.html b/doc/html/pcre2test.html index 8b6d35d..7f72779 100644 --- a/doc/html/pcre2test.html +++ b/doc/html/pcre2test.html @@ -1239,6 +1239,8 @@ pattern, but can be overridden by modifiers on the subject. match_limit=<n> set a match limit memory show heap memory usage null_context match with a NULL context + null_replacement substitute with NULL replacement + null_subject match with NULL subject offset=<n> set starting offset offset_limit=<n> set offset limit ovector=<n> set size of output vector @@ -1668,7 +1670,7 @@ When testing pcre2_substitute(), this modifier also has the effect of passing the replacement string as zero-terminated.


-Passing a NULL context +Passing a NULL context, subject, or replacement

Normally, pcre2test passes a context block to pcre2_match(), @@ -1678,6 +1680,11 @@ testing that the matching and substitution functions behave correctly in this case (they use default values). This modifier cannot be used with the find_limits or substitute_callout modifiers.

+

+Similarly, for testing purposes, if the null_subject or +null_replacement modifier is set, the subject or replacement string +pointers are passed as NULL, respectively, to the relevant functions. +


THE ALTERNATIVE MATCHING FUNCTION

By default, pcre2test uses the standard PCRE2 matching function, @@ -2122,7 +2129,7 @@ Cambridge, England.


REVISION

-Last updated: 30 August 2021 +Last updated: 28 November 2021
Copyright © 1997-2021 University of Cambridge.
diff --git a/doc/pcre2.txt b/doc/pcre2.txt index 105762e..7e96413 100644 --- a/doc/pcre2.txt +++ b/doc/pcre2.txt @@ -3524,7 +3524,9 @@ CREATING A NEW STRING WITH SUBSTITUTIONS does not happen by default. PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the - match_data argument is NULL. + match_data argument is NULL or if the subject or replacement arguments + are NULL. For backward compatibility reasons an exception is made for + the replacement argument if the rlength argument is also 0. PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the replacement string, with more particular errors being PCRE2_ER- diff --git a/doc/pcre2test.1 b/doc/pcre2test.1 index 3b449ae..9707f88 100644 --- a/doc/pcre2test.1 +++ b/doc/pcre2test.1 @@ -1,4 +1,4 @@ -.TH PCRE2TEST 1 "30 August 2021" "PCRE 10.38" +.TH PCRE2TEST 1 "28 November 2021" "PCRE 10.40" .SH NAME pcre2test - a program for testing Perl-compatible regular expressions. .SH SYNOPSIS @@ -1206,6 +1206,8 @@ pattern, but can be overridden by modifiers on the subject. match_limit= set a match limit memory show heap memory usage null_context match with a NULL context + null_replacement substitute with NULL replacement + null_subject match with NULL subject offset= set starting offset offset_limit= set offset limit ovector= set size of output vector @@ -1629,7 +1631,7 @@ When testing \fBpcre2_substitute()\fP, this modifier also has the effect of passing the replacement string as zero-terminated. . . -.SS "Passing a NULL context" +.SS "Passing a NULL context, subject, or replacement" .rs .sp Normally, \fBpcre2test\fP passes a context block to \fBpcre2_match()\fP, @@ -1638,6 +1640,10 @@ If the \fBnull_context\fP modifier is set, however, NULL is passed. This is for testing that the matching and substitution functions behave correctly in this case (they use default values). This modifier cannot be used with the \fBfind_limits\fP or \fBsubstitute_callout\fP modifiers. +.P +Similarly, for testing purposes, if the \fBnull_subject\fP or +\fBnull_replacement\fP modifier is set, the subject or replacement string +pointers are passed as NULL, respectively, to the relevant functions. . . .SH "THE ALTERNATIVE MATCHING FUNCTION" @@ -2103,6 +2109,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 30 August 2021 +Last updated: 28 November 2021 Copyright (c) 1997-2021 University of Cambridge. .fi diff --git a/doc/pcre2test.txt b/doc/pcre2test.txt index 8db3f10..06456a1 100644 --- a/doc/pcre2test.txt +++ b/doc/pcre2test.txt @@ -1111,6 +1111,8 @@ SUBJECT MODIFIERS match_limit= set a match limit memory show heap memory usage null_context match with a NULL context + null_replacement substitute with NULL replacement + null_subject match with NULL subject offset= set starting offset offset_limit= set offset limit ovector= set size of output vector @@ -1499,7 +1501,7 @@ SUBJECT MODIFIERS When testing pcre2_substitute(), this modifier also has the effect of passing the replacement string as zero-terminated. - Passing a NULL context + Passing a NULL context, subject, or replacement Normally, pcre2test passes a context block to pcre2_match(), pcre2_dfa_match(), pcre2_jit_match() or pcre2_substitute(). If the @@ -1508,6 +1510,10 @@ SUBJECT MODIFIERS in this case (they use default values). This modifier cannot be used with the find_limits or substitute_callout modifiers. + Similarly, for testing purposes, if the null_subject or null_replace- + ment modifier is set, the subject or replacement string pointers are + passed as NULL, respectively, to the relevant functions. + THE ALTERNATIVE MATCHING FUNCTION @@ -1933,5 +1939,5 @@ AUTHOR REVISION - Last updated: 30 August 2021 + Last updated: 28 November 2021 Copyright (c) 1997-2021 University of Cambridge. diff --git a/src/pcre2test.c b/src/pcre2test.c index 8062467..300c255 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -516,6 +516,8 @@ so many of them that they are split into two fields. */ #define CTL2_CALLOUT_NO_WHERE 0x00000200u #define CTL2_CALLOUT_EXTRA 0x00000400u #define CTL2_ALLVECTOR 0x00000800u +#define CTL2_NULL_SUBJECT 0x00001000u +#define CTL2_NULL_REPLACEMENT 0x00002000u #define CTL2_NL_SET 0x40000000u /* Informational */ #define CTL2_BSR_SET 0x80000000u /* Informational */ @@ -706,6 +708,8 @@ static modstruct modlist[] = { { "notempty_atstart", MOD_DAT, MOD_OPT, PCRE2_NOTEMPTY_ATSTART, DO(options) }, { "noteol", MOD_DAT, MOD_OPT, PCRE2_NOTEOL, DO(options) }, { "null_context", MOD_PD, MOD_CTL, CTL_NULLCONTEXT, PO(control) }, + { "null_replacement", MOD_DAT, MOD_CTL, CTL2_NULL_REPLACEMENT, DO(control2) }, + { "null_subject", MOD_DAT, MOD_CTL, CTL2_NULL_SUBJECT, DO(control2) }, { "offset", MOD_DAT, MOD_INT, 0, DO(offset) }, { "offset_limit", MOD_CTM, MOD_SIZ, 0, MO(offset_limit)}, { "ovector", MOD_DAT, MOD_INT, 0, DO(oveccount) }, @@ -7064,9 +7068,14 @@ pp = memmove(dbuffer + dbuffer_size - len - c, dbuffer, len + c); VALGRIND_MAKE_MEM_NOACCESS(dbuffer, dbuffer_size - (len + c)); #endif -/* Now pp points to the subject string. POSIX matching is only possible in -8-bit mode, and it does not support timing or other fancy features. Some were -checked at compile time, but we need to check the match-time settings here. */ +/* Now pp points to the subject string, but if null_subject was specified, set +it to NULL to test PCRE2's behaviour. */ + +if ((dat_datctl.control2 & CTL2_NULL_SUBJECT) != 0) pp = NULL; + +/* POSIX matching is only possible in 8-bit mode, and it does not support +timing or other fancy features. Some were checked at compile time, but we need +to check the match-time settings here. */ #ifdef SUPPORT_PCRE2_8 if ((pat_patctl.control & CTL_POSIX) != 0) @@ -7293,6 +7302,7 @@ if (dat_datctl.replacement[0] != 0) uint8_t *pr; uint8_t rbuffer[REPLACE_BUFFSIZE]; uint8_t nbuffer[REPLACE_BUFFSIZE]; + uint8_t *rbptr; uint32_t xoptions; uint32_t emoption; /* External match option */ PCRE2_SIZE j, rlen, nsize, erroroffset; @@ -7442,10 +7452,15 @@ if (dat_datctl.replacement[0] != 0) { PCRE2_SET_SUBSTITUTE_CALLOUT(dat_context, NULL, NULL); /* No callout */ } + + /* There is a special option to set the replacement to NULL in order to test + that case. */ + + rbptr = ((dat_datctl.control2 & CTL2_NULL_REPLACEMENT) == 0)? rbuffer : NULL; PCRE2_SUBSTITUTE(rc, compiled_code, pp, arg_ulen, dat_datctl.offset, dat_datctl.options|xoptions, match_data, use_dat_context, - rbuffer, rlen, nbuffer, &nsize); + rbptr, rlen, nbuffer, &nsize); if (rc < 0) {