From: Michael Vogel Date: Mon, 5 May 2014 22:33:56 +0000 (+0200) Subject: Plaintext: Regular expressions were too greedy. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=407ea6977ac638500294032f272c0baf81043033;p=friendica.git Plaintext: Regular expressions were too greedy. --- diff --git a/include/plaintext.php b/include/plaintext.php index 65b0b347d3..0c985e05c0 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -22,10 +22,12 @@ function get_attached_data($body) { $attacheddata = $data[2]; - if (preg_match("/\[img\](.*?)\[\/img\]/ism", $attacheddata, $matches)) + $URLSearchString = "^\[\]"; + + if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) $post["image"] = $matches[1]; - if (preg_match("/\[bookmark\=(.*?)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) { + if (preg_match("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) { $post["url"] = $matches[1]; $post["title"] = $matches[2]; } @@ -54,7 +56,8 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false) { // if nothing is found, it maybe having an image. if (!isset($post["type"])) { - if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) { + $URLSearchString = "^\[\]"; + if (preg_match_all("(\[url=([$URLSearchString]*)\]\s*\[img\]([$URLSearchString]*)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) { if (count($pictures) == 1) { // Checking, if the link goes to a picture $data = parseurl_getsiteinfo($pictures[0][1], true); @@ -88,7 +91,7 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false) { $post["image"] = $pictures[0][2]; $post["text"] = $body; } - } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) { + } elseif (preg_match_all("(\[img\]([$URLSearchString]*)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) { if (count($pictures) == 1) { $post["type"] = "photo"; $post["image"] = $pictures[0][1];