From 24df21367e328ec9ecd19e3cc4a56c4904d20468 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Mon, 13 May 2013 15:13:38 -0400 Subject: [PATCH] worked on CRM-12551, fix the datatable break due to tab character --- CRM/Utils/JSON.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index c9b4f16e76..986ed4f1c2 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -102,6 +102,17 @@ class CRM_Utils_JSON { return $json; } + /** + * This function is used to encode data for dataTable plugin + * + * @param array $params associated array of row elements + * @param int $sEcho datatable needs this to make it more secure + * @param int $iTotal total records + * @param int $iFilteredTotal total records on a page + * @param array $selectorElements selector elements + * @return string + * + */ static function encodeDataTableSelector($params, $sEcho, $iTotal, $iFilteredTotal, $selectorElements) { $sOutput = '{'; $sOutput .= '"sEcho": ' . intval($sEcho) . ', '; @@ -115,13 +126,14 @@ class CRM_Utils_JSON { if ($addcomma) { $sOutput .= ","; } - //$sOutput .= '"'.addslashes($value[$element]).'"'; //CRM-7130 --lets addslashes to only double quotes, //since we are using it to quote the field value. //str_replace helps to provide a break for new-line $sOutput .= '"' . addcslashes(str_replace(array("\r\n", "\n", "\r"), '
', $value[$element]), '"\\') . '"'; + //remove extra spaces and tab character that breaks dataTable CRM-12551 + $sOutput = preg_replace("/\s+/", " ", $sOutput); $addcomma = TRUE; } $sOutput .= "],"; -- 2.25.1