summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-01-22 20:19:27 +0100
committerDerek Jones <derek.jones@ellislab.com>2008-01-22 20:19:27 +0100
commit9468f3ebe207f73aa5871b5eeca26184dbccbfd1 (patch)
treec31d016915154f6b4dd0642889e914d777e77964
parente7c4c3211c05c7bde09dbdbac77647461f52bfdb (diff)
fixed bug #3156 in highlight_code() where PHP tags were not being converted properly. Also added protection for asp and inline style script delimiters, and removed an empty span to make outputted code valid
-rw-r--r--system/helpers/text_helper.php13
-rw-r--r--user_guide/changelog.html1
2 files changed, 9 insertions, 5 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 9620e03e1..8b671140d 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -259,8 +259,9 @@ function highlight_code($str)
// Replace any existing PHP tags to temporary markers so they don't accidentally
// break the string out of PHP, and thus, thwart the highlighting.
- $str = str_replace(array('&lt;?php', '?&gt;', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str);
-
+ $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'),
+ array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
+
// The highlight_string function requires that the text be surrounded
// by PHP tags. Since we don't know if A) the submitted text has PHP tags,
// or B) whether the PHP tags enclose the entire string, we will add our
@@ -279,14 +280,16 @@ function highlight_code($str)
$str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
}
- // Remove our artificially added PHP
+ // Remove our artificially added PHP and the empty span that results from our temp markers
$str = preg_replace("#\<code\>.+?//tempstart\<br />\</span\>#is", "<code>\n", $str);
$str = preg_replace("#\<code\>.+?//tempstart\<br />#is", "<code>\n", $str);
$str = preg_replace("#//tempend.+#is", "</span>\n</code>", $str);
+ $str = preg_replace("#\<span style=\"color: \#FF8000\"\></span>\n</code>#is", "\n</code>", $str);
// Replace our markers back to PHP tags.
- $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('&lt;?php', '?&gt;', '\\'), $str); //<?
-
+ $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);
+
return $str;
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 530a612c3..b4c6e623c 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -154,6 +154,7 @@ Change Log
<ul>
<li>Removed an extraneous call to loading models (#3286).</li>
+ <li>Fixed a bug (#3156) in Text Helper highlight_code() causing PHP tags to be handled incorrectly.</li>
<li>Fixed a bug (#3289) in the File Helper where temp files in directories being tested with is_really_writable() were not being handled properly</li>
<li>Fixed a bug (#3279) where the Email class was sending the wrong Content-Transfer-Encoding for some character sets.</li>
<li>Fixed a bug (#3268) where the Router could leave '/' as the path.</li>