From ad5187383d35c1bace5f3e53afe1449848cbf93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Sat, 27 Aug 2016 09:12:46 +0200 Subject: [PATCH] Automatically save SQL query in browser local storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ..when available rather than in cookie as we do not want to send huge cookies with SQL query there and back. Issue #12251 Issue phpmyadmin/docker#32 Signed-off-by: Michal Čihař --- ChangeLog | 1 + js/functions.js | 4 +++- js/sql.js | 27 +++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 413e3f6b6e..c0488b0478 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ phpMyAdmin - ChangeLog - issue #12497 Missing escaping of configuration used in SQL (hide_db and only_db) - issue #12476 Add error checking in reading advisory rules file - issue #12477 Add checking missing elements and confirming element types from json_decode +- issue #12251 Automatically save SQL query in browser local storage rather than in cookie 4.6.4 (2016-08-16) - issue [security] Weaknesses with cookie encryption, see PMASA-2016-29 diff --git a/js/functions.js b/js/functions.js index 0304126695..bace1bf56d 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1164,7 +1164,9 @@ function insertQuery(queryType) } return; } else if (queryType == "saved") { - if ($.cookie('auto_saved_sql')) { + if (isStorageSupported('localStorage') && typeof window.localStorage.auto_saved_sql != 'undefined') { + setQuery(window.localStorage.auto_saved_sql); + } else if ($.cookie('auto_saved_sql')) { setQuery($.cookie('auto_saved_sql')); } else { PMA_ajaxShowMessage(PMA_messages.strNoAutoSavedQuery); diff --git a/js/sql.js b/js/sql.js index 8a8ee57320..c379420d31 100644 --- a/js/sql.js +++ b/js/sql.js @@ -36,6 +36,23 @@ function PMA_urlencode(str) } } +/** + * Saves SQL query in local storage or cooie + * + * @param string SQL query + * @return void + */ +function PMA_autosaveSQL(query) +{ + if (query) { + if (isStorageSupported('localStorage')) { + window.localStorage.auto_saved_sql = query; + } else { + $.cookie('auto_saved_sql', query); + } + } +} + /** * Get the field name for the current field. Required to construct the query * for grid editing @@ -135,17 +152,11 @@ AJAX.registerOnload('sql.js', function () { $(function () { if (codemirror_editor) { codemirror_editor.on('change', function () { - var query = codemirror_editor.getValue(); - if (query) { - $.cookie('auto_saved_sql', query); - } + PMA_autosaveSQL(codemirror_editor.getValue()); }); } else { $('#sqlquery').on('input propertychange', function () { - var query = $('#sqlquery').val(); - if (query) { - $.cookie('auto_saved_sql', query); - } + PMA_autosaveSQL($('#sqlquery').val()); }); } });