Parser: Handle regex failure in extractBody method
Add a check for regex failure in the extractBody method and throw a RuntimeException with the error details if preg_replace returns null. Bug: T388729 Change-Id: I59abad3a58ccd6edc6517b13a56d8253ba0e0928 (cherry picked from commit 3b297d37dd368d1d66f7afd78851bbb7a47cab0b)
This commit is contained in:
parent
21ec3daaa7
commit
e7fa1c246c
1 changed files with 4 additions and 0 deletions
|
|
@ -6484,6 +6484,10 @@ class Parser {
|
|||
*/
|
||||
public static function extractBody( string $text ): string {
|
||||
$text = preg_replace( '!^.*?<body[^>]*>!s', '', $text, 1 );
|
||||
if ( $text === null ) {
|
||||
// T388729: this should never happen
|
||||
throw new RuntimeException( 'Regex failed: ' . preg_last_error() );
|
||||
}
|
||||
$text = preg_replace( '!</body>\s*</html>\s*$!', '', $text, 1 );
|
||||
return $text;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue