From 376cc353dcddbc7ed4568c6cc4ffdbad147bf15f Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Thu, 4 Aug 2011 18:27:37 +0800 Subject: [PATCH] Recent table: fix bug - not work for db or table name containing custom characters --- js/navigation.js | 6 +++--- libraries/RecentTable.class.php | 17 ++++++++++------- libraries/common.inc.php | 31 ++++++++++++++++--------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index 5ce805c278..33e829ce21 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -199,9 +199,9 @@ $(document).ready(function(){ /* Jump to recent table */ $('#recentTable').change(function() { if (this.value != '') { - var arr = this.value.split('.'); - window.parent.setDb(arr[0]); - window.parent.setTable(arr[1]); + var arr = jQuery.parseJSON(this.value); + window.parent.setDb(arr['db']); + window.parent.setTable(arr['table']); window.parent.refreshMain($('#LeftDefaultTabTable')[0].value); } }); diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index bfb60818fa..def9c37c03 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -82,7 +82,7 @@ class PMA_RecentTable $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); if (isset($row[0])) { - return json_decode($row[0]); + return json_decode($row[0], true); } else { return array(); } @@ -142,7 +142,8 @@ class PMA_RecentTable $html = ''; if (count($this->tables)) { foreach ($this->tables as $table) { - $html .= ''; + $html .= ''; } } else { $html .= ''; @@ -159,7 +160,7 @@ class PMA_RecentTable { $html = ''; - $html .= ''; $html .= $this->getHtmlSelectOption(); $html .= ''; @@ -176,12 +177,14 @@ class PMA_RecentTable */ public function add($db, $table) { - $table_str = $db . '.' . $table; + $table_arr = array(); + $table_arr['db'] = $db; + $table_arr['table'] = $table; // add only if this is new table - if (! isset($this->tables[0]) || $this->tables[0] != $table_str) { - array_unshift($this->tables, $table_str); - $this->tables = array_merge(array_unique($this->tables)); + if (! isset($this->tables[0]) || $this->tables[0] != $table_arr) { + array_unshift($this->tables, $table_arr); + $this->tables = array_merge(array_unique($this->tables, SORT_REGULAR)); $this->trim(); if (isset($this->pma_table)) { return $this->saveToDb(); diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 2b2cf60a9f..beb7f7b6c7 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -510,21 +510,22 @@ if (PMA_isValid($_REQUEST['db'])) { */ $GLOBALS['table'] = ''; if (PMA_isValid($_REQUEST['table'])) { - // check if specified table contain db name - if (strpos($_REQUEST['table'], '.')) { - $splitted = explode('.', $_REQUEST['table']); - if (count($splitted) == 2) { // make sure the format is "db.table" - $GLOBALS['db'] = $splitted[0]; - $GLOBALS['url_params']['db'] = $GLOBALS['db']; - $GLOBALS['table'] = $splitted[1]; - $GLOBALS['url_params']['table'] = $GLOBALS['table']; - } - } else { - // can we strip tags from this? - // only \ and / is not allowed in table names for MySQL - $GLOBALS['table'] = $_REQUEST['table']; - $GLOBALS['url_params']['table'] = $GLOBALS['table']; - } + // can we strip tags from this? + // only \ and / is not allowed in table names for MySQL + $GLOBALS['table'] = $_REQUEST['table']; + $GLOBALS['url_params']['table'] = $GLOBALS['table']; +} + +/** + * Store currently selected recent table. + * Affect $GLOBALS['db'] and $GLOBALS['table'] + */ +if (PMA_isValid($_REQUEST['selected_recent_table'])) { + $recent_table = json_decode($_REQUEST['selected_recent_table'], true); + $GLOBALS['db'] = $recent_table['db']; + $GLOBALS['url_params']['db'] = $GLOBALS['db']; + $GLOBALS['table'] = $recent_table['table']; + $GLOBALS['url_params']['table'] = $GLOBALS['table']; } /**