From bdb1cab348a750e2047ab0e26797a227d9664763 Mon Sep 17 00:00:00 2001
From: jinhofer
Date: Fri, 13 Nov 2015 17:25:35 -0600
Subject: [PATCH] MDL-51483 lib/moodlelib.php: Added conditional checks to
shorten_text
---
lib/medialib.php | 16 ++++++++--------
lib/moodlelib.php | 18 +++++++++++++++++-
lib/tests/moodlelib_test.php | 8 ++++++++
webservice/amf/testclient/index.php | 4 ++--
4 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/lib/medialib.php b/lib/medialib.php
index 34c282908cd..df3eef40239 100644
--- a/lib/medialib.php
+++ b/lib/medialib.php
@@ -811,7 +811,7 @@ class core_media_player_wmp extends core_media_player {
-
+
@@ -875,7 +875,7 @@ class core_media_player_qt extends core_media_player {
-
+
@@ -934,14 +934,14 @@ class core_media_player_rm extends core_media_player {
data="$url" width="$width" height="$height"">
-
+
@@ -989,7 +989,7 @@ class core_media_player_swf extends core_media_player {
-
+
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 8fd08cdb637..55c8b697ab6 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -7691,6 +7691,18 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {
'tag' => core_text::strtolower($tagmatchings[1]),
'pos' => core_text::strlen($truncate),
);
+ } else if (preg_match('/^$/s', $linematchings[1], $tagmatchings)) {
+ $tagdetails[] = (object) array(
+ 'open' => false,
+ 'tag' => core_text::strtolower('if'),
+ 'pos' => core_text::strlen($truncate),
+ );
}
}
// Add html-tag to $truncate'd text.
@@ -7776,7 +7788,11 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {
// Close all unclosed html-tags.
foreach ($opentags as $tag) {
- $truncate .= '' . $tag . '>';
+ if ($tag === 'if') {
+ $truncate .= '';
+ } else {
+ $truncate .= '' . $tag . '>';
+ }
}
return $truncate;
diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php
index 78b2a2d16bd..c976de32987 100644
--- a/lib/tests/moodlelib_test.php
+++ b/lib/tests/moodlelib_test.php
@@ -869,6 +869,14 @@ class core_moodlelib_testcase extends advanced_testcase {
"tags that ...
", shorten_text($text));
}
+ public function test_shorten_text_with_tags_and_html_comment() {
+ $text = "Long text with ".
+ "tags that will ".
+ "be chopped off but should be added back again
";
+ $this->assertEquals("Long text with " .
+ "tags that ...
", shorten_text($text));
+ }
+
public function test_shorten_text_with_entities() {
// Remember to allow 3 chars for the final '...'.
// ......123456789012345678901234567_____890...
diff --git a/webservice/amf/testclient/index.php b/webservice/amf/testclient/index.php
index 7d84acd7373..fbb3e714aec 100644
--- a/webservice/amf/testclient/index.php
+++ b/webservice/amf/testclient/index.php
@@ -48,14 +48,14 @@ $output = <<
-
+