From 407ea6977ac638500294032f272c0baf81043033 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 6 May 2014 00:33:56 +0200 Subject: [PATCH] Plaintext: Regular expressions were too greedy. --- include/plaintext.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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];