-
Notifications
You must be signed in to change notification settings - Fork 242
Add pcre2_substitute checks to enforce subject hasn't changed #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds three new error codes to pcre2_substitute when using PCRE2_SUBSTITUTE_MATCHED: * PCRE2_ERROR_DIFFERENT_SUBJECT: returned if if the subject pointer you passed is different from the prior call to pcre2_match * PCRE2_ERROR_DIFFERENT_LENGTH: if the computed length differs from the pcre2_match call (i.e. after processing PCRE2_ZERO_TERMINATED) * PCRE2_ERROR_DIFFERENT_OFFSET if the start offset differs from the pcre2_match call. (cherry picked from commit 0d7e6d5)
Specficially, when pcre2_match is called with PCRE2_COPY_MATCHED_SUBJECT, and then pcre2_substitute is called with PCRE2_SUBSTITUTE_MATCHED, the subject data saved by the PCRE2_COPY_MATCHED_SUBJECT call will be used, In addition, the subject to pcre2_substitute can be NULL. Moreover, the length can also be PCRE2_ZERO_TERMINATE, and the original length will also be used. (cherry picked from commit 9651bcf)
The following subject modifiers have been added:
* substitute_subject=<string>
like replace=<string> but no [...] syntax
This is for use with substitute_matched, it makes pcre2test use the given string for
the call to pcre2_substitute (instead of the subject passed to pcre2_match)
(cherry picked from commit 598ad44)
FYI I recall moving some of the I also noticed you deleted my
My last commit on my pull request also adds a Then the documentation can roughly say:
How about a sentence like this: Otherwise you're just wasting memory requiring the caller of
In my main However I think I'm missing a few modifiers, so when cherry picking that over, make sure the bit that says: Should also have: And modify |
|
I noticed your most recent commit, 071b626 seems to prohibit using |
I have already merged quite a few of your commits to master. The CI testing does run the tests with
Good point. I actually deleted Now that you mention it, I feel mildly guilty about that exception for 0-length subjects. I will replace the
I'll get to that! I'm just merging your work commit-by-commit. To be honest, I'm not sure what the point of PCRE2_COPY_MATCHED_SUBJECT is at all. If the caller wants to copy the subject, then... they can just do that!?! Why PCRE2 has to do the copy is unclear to me.
I think I'm actually not going to add pcre2test modifiers for all these invalid edge cases. pcre2test should allow us to exercise all the documented-legal behaviour in PCRE2, and some of the illegal stuff, but there's so much possible illegal behaviour it would be wild if we added modifiers for them all (particularly if that modifier is only going to be used in literally one single test in the whole suite). Instead I think I am going to move those tests into a dedicated "unittest()" function that exercises specific error conditions. |
Agreed. I just think if a feature already exists it shouldn't be arbitrarily limited.
That would have been much easier than modifying |
Is the CI running my new tests? I didn't notice any of your comments modifying the CI or |
I'll move those tests into one of the existing test files. Actually several - we need to test some "FASTJIT" paths and some DFA paths, which we can't do all in the same input file, because the input files are tested conditionally on whether PCRE2 was compiled with the required features. |
|
Hi @IsaacOscar, I've finished with this PR I think. I ended up making quite a few unrelated changes to pcre2test that appear to be unrelated, but turned out to be required or prompted by the other improvements. I've preserved the tests of yours that I could, given the reduced number of pcre2test modifiers, and moved the remainder into the unittest() function. Thank you again for your contribution. Please let me know if you are happy with the behaviour, documentation, tests... |
Everything looks great, modulo my above disagreement about |
|
Thank you for reviewing and collaborating. I appreciate why you might want to make |
With thanks to @IsaacOscar.
This splits out two commits from Isaac's open PR.
I have:
_match.cfiles, by preserving a little more of the original behaviour. The main change is now simply that we set thesubjectfield when returning NOMATCH.