Skip to content

Commit

Permalink
Merge pull request #46 from slackhq/add-preg-error-handling
Browse files Browse the repository at this point in the history
Adding error handling to get more information
  • Loading branch information
JPolacek authored Feb 9, 2023
2 parents 9c397c9 + 4a61674 commit 8ffccd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os: [ ubuntu ]
hhvm:
- '4.153'
runs-on: ${{matrix.os}}-latest
runs-on: ${{matrix.os}}-20.04
steps:
- uses: actions/checkout@v2
# Runs a single command using the runners shell
Expand Down
10 changes: 8 additions & 2 deletions src/Lexer.hack
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,14 @@ class HTMLPurifier_Lexer {
*/
public function extractBody(string $html): string {
$matches = vec[];
$result = \preg_match_with_matches('|(.*?)<body[^>]*>(.*)</body>|is', $html, inout $matches);
if ($result) {
$error = null;
$result = \preg_match_with_matches_and_error('|(.*?)<body[^>]*>(.*)</body>|is', $html, inout $matches, inout $error);
if ($error is nonnull) {
// Adding some better error tracing here to get more info out of what's wrong with the regex on line 287
// The error codes can be found here: https://github.com/facebook/hhvm/blob/c5da95da0bd1f0ba9524e6a6e020ab824c1e75b0/hphp/runtime/base/preg.h#L42
throw new \Error("Error in preg_match_with_matches_and_error: $error", \E_USER_WARNING);
}
else if ($result) {
// Make sure it's not in a comment
$comment_start = \strrpos($matches[1], '<!--');
$comment_end = \strrpos($matches[1], '-->');
Expand Down

0 comments on commit 8ffccd0

Please sign in to comment.