From 6e59c0ffb96998f9d4e3ad87f05c6091bcc7e8de Mon Sep 17 00:00:00 2001 From: vdbhb59 Date: Fri, 5 Sep 2025 14:47:12 +0530 Subject: [PATCH] Brave crash fix https://git.lolcat.ca/lolcat/4get/commit/8613c1e0f49f44e54d0057b379cef127d32c3e1d --- lib/fuckhtml.php | 62 ++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/lib/fuckhtml.php b/lib/fuckhtml.php index c90d1e8..66b89a9 100644 --- a/lib/fuckhtml.php +++ b/lib/fuckhtml.php @@ -240,13 +240,13 @@ class fuckhtml{ public function getElementsByFuzzyAttributeValue(string $name, string $value, $collection = null){ $elems = $this->getElementsByAttributeName($name, $collection); - + $value = explode( " ", trim( preg_replace( - '/ \s+/', + '/\s+/', " ", $value ) @@ -270,7 +270,7 @@ class fuckhtml{ ) ) ); - + $ac = count($attrib_value); $nc = count($value); $cr = 0; @@ -551,6 +551,33 @@ class fuckhtml{ switch($json[$i]){ + case "\"": + case "'": + if( + $i > 2 || + ( + ( + $json[$i - 1] === "\\" && + $json[$i - 2] === "\\" + ) || + $json[$i - 1] !== "\\" + ) + ){ + // found a non-escaped quote + + if($in_quote === null){ + + // open quote + $in_quote = $json[$i]; + + }elseif($in_quote === $json[$i]){ + + // close quote + $in_quote = null; + } + } + break; + case "[": if($in_quote === null){ @@ -586,37 +613,20 @@ class fuckhtml{ $object_level--; } break; - - case "\"": - case "'": - if( - $i !== 0 && - $json[$i - 1] !== "\\" - ){ - // found a non-escaped quote - - if($in_quote === null){ - - // open quote - $in_quote = $json[$i]; - }elseif($in_quote === $json[$i]){ - - // close quote - $in_quote = null; - } - } - break; } if( - $start !== null && $array_level === 0 && - $object_level === 0 + $object_level === 0 && + $start !== null ){ return substr($json, $start, $i - $start + 1); break; } } + + // fallback + return "[]"; } -} +} \ No newline at end of file