diff options
author | Zach Copley <zach@status.net> | 2010-03-01 14:58:06 -0800 |
---|---|---|
committer | Zach Copley <zach@status.net> | 2010-03-01 15:02:36 -0800 |
commit | ea6072fdd71f9b7ce86d13a3d52271f77bd8b02c (patch) | |
tree | 85e77719b335033c30733a36a08b9cdeae305c6c | |
parent | 6c3bc028fa6a49f51be28dfa387b978be97e1460 (diff) |
Upgrade XML output scrubbing to better deal with newline and a few other chars0.8.x
-rw-r--r-- | lib/util.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/util.php b/lib/util.php index 0052090f6..0a6725c7f 100644 --- a/lib/util.php +++ b/lib/util.php @@ -590,8 +590,28 @@ function common_shorten_links($text) function common_xml_safe_str($str) { - // Neutralize control codes and surrogates - return preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str); + // Replace common eol and extra whitespace input chars + $unWelcome = array( + "\t", // tab + "\n", // newline + "\r", // cr + "\0", // null byte eos + "\x0B" // vertical tab + ); + + $replacement = array( + ' ', // single space + ' ', + '', // nothing + '', + ' ' + ); + + $str = str_replace($unWelcome, $replacement, $str); + + // Neutralize any additional control codes and UTF-16 surrogates + // (Twitter uses '*') + return preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str); } function common_tag_link($tag) |