From e66eb537d8b3fa97cacd0e70dc2bbb576ac02a86 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 26 Oct 2017 08:58:23 +0000 Subject: [PATCH] datatable refresh prb when source is in CrLf instead of Lf : * add a try/catch block in the JS code * properly escape string returned This can happen for example when checking out with git-svn on Windows with core.autocrlf=auto SVN:trunk[5089] --- application/datatable.class.inc.php | 2 +- js/datatable.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index b92ceded3..672cc40b2 100644 --- a/application/datatable.class.inc.php +++ b/application/datatable.class.inc.php @@ -606,7 +606,7 @@ EOF $iPageSize = ($iDefaultPageSize < 1) ? 1 : $iDefaultPageSize; $iPageIndex = 1 + floor($iStart / $iPageSize); $sHtml = $this->GetPager($oPage, $iPageSize, $iDefaultPageSize, $iPageIndex); - $oPage->add_ready_script("$('#pager{$this->iListId}').html('".str_replace("\n", ' ', addslashes($sHtml))."');"); + $oPage->add_ready_script("$('#pager{$this->iListId}').html('".json_encode($sHtml)."');"); if ($iDefaultPageSize < 1) { $oPage->add_ready_script("$('#pager{$this->iListId}').parent().hide()"); diff --git a/js/datatable.js b/js/datatable.js index 9ea117c3b..8c8bc054a 100644 --- a/js/datatable.js +++ b/js/datatable.js @@ -91,9 +91,19 @@ $(function() } // End of workaround - me.element.find('.datacontents').html(data); - // restore the sort order on columns - me.element.find('table.listResults').trigger('fakesorton', [aCurrentSort]); + try { + me.element.find('.datacontents').html(data); + // restore the sort order on columns + me.element.find('table.listResults').trigger('fakesorton', [aCurrentSort]); + } catch (e) { + // ugly hacks for IE 8/9 first... + if (!window.console) console.error = {}; + if (!window.console.error) { + console.error = function () { + }; + } + console.error("Can not inject data : "+data); + } me.element.unblock(); }, 'html' );