From 1fc566fd90d838d35dfa5251f26deb48d15780a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Jan 2018 17:35:32 +0100 Subject: [PATCH] Share code for parsing data-post attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can include leading question mark and we should deal with it in all locations. Fixes #13913 Signed-off-by: Michal Čihař --- js/ajax.js | 8 ++------ js/db_structure.js | 4 ++-- js/functions.js | 13 +++++++++++++ js/rte.js | 4 ++-- js/sql.js | 5 +++-- js/tbl_structure.js | 4 ++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 0254b0bc16..69a1cc2abb 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -283,15 +283,11 @@ var AJAX = { var url = isLink ? href : $(this).attr('action'); var params = 'ajax_request=true&ajax_page_request=true'; - var dataPost = AJAX.source.attr('data-post'); + var dataPost = AJAX.source.getPostData(); if (! isLink) { params += '&' + $(this).serialize(); } else if (dataPost) { - // Strip possible leading ? - if (dataPost.startsWith('?')) { - dataPost = dataPost.substr(1); - } - params += '&' + AJAX.source.attr('data-post'); + params += '&' + dataPost; isLink = false; } if (! (history && history.pushState)) { diff --git a/js/db_structure.js b/js/db_structure.js index 7e64f59556..7c0da763b6 100644 --- a/js/db_structure.js +++ b/js/db_structure.js @@ -298,7 +298,7 @@ AJAX.registerOnload('db_structure.js', function () { $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) { PMA_ajaxShowMessage(PMA_messages.strProcessingRequest); - var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post')); + var params = getJSConfirmCommonParam(this, $this_anchor.getPostData()); $.post(url, params, function (data) { if (typeof data !== 'undefined' && data.success === true) { @@ -360,7 +360,7 @@ AJAX.registerOnload('db_structure.js', function () { $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) { var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest); - var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post')); + var params = getJSConfirmCommonParam(this, $this_anchor.getPostData()); $.post(url, params, function (data) { if (typeof data !== 'undefined' && data.success === true) { diff --git a/js/functions.js b/js/functions.js index 752242a095..b449070b5b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -5086,3 +5086,16 @@ function configGet(key, cached=true) }); return JSON.parse(localStorage.getItem(key)); } + +/** + * Return POST data as stored by Util::linkOrButton + */ +jQuery.fn.getPostData = function() { + var dataPost = this.attr('data-post'); + // Strip possible leading ? + if (dataPost.startsWith('?')) { + dataPost = dataPost.substr(1); + } + return dataPost; +}; + diff --git a/js/rte.js b/js/rte.js index 5f89835d54..17cfaace74 100644 --- a/js/rte.js +++ b/js/rte.js @@ -401,7 +401,7 @@ RTE.COMMON = { * the AJAX message shown to the user */ var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest); - var params = getJSConfirmCommonParam(this, $this.attr('data-post')); + var params = getJSConfirmCommonParam(this, $this.getPostData()); $.post(url, params, function (data) { if (data.success === true) { /** @@ -476,7 +476,7 @@ RTE.COMMON = { * @var $curr_row Object containing reference to the current row */ var $curr_row = $anchor.parents('tr'); - var params = getJSConfirmCommonParam(this, $anchor.attr('data-post')); + var params = getJSConfirmCommonParam(this, $anchor.getPostData()); $.post($anchor.attr('href'), params, function (data) { returnCount++; if (data.success === true) { diff --git a/js/sql.js b/js/sql.js index a6f5348c45..9a16f1c642 100644 --- a/js/sql.js +++ b/js/sql.js @@ -188,8 +188,9 @@ AJAX.registerOnload('sql.js', function () { $link.PMA_confirm(question, $link.attr('href'), function (url) { $msgbox = PMA_ajaxShowMessage(); var params = 'ajax_request=1&is_js_confirmed=1'; - if ($link.attr('data-post')) { - params += '&' + $link.attr('data-post'); + var postData = $link.getPostData(); + if (postData) { + params += '&' + postData; } $.post(url, params, function (data) { if (data.success) { diff --git a/js/tbl_structure.js b/js/tbl_structure.js index b4d0b84beb..af24b5936b 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -183,7 +183,7 @@ AJAX.registerOnload('tbl_structure.js', function () { var $this_anchor = $(this); $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) { var $msg = PMA_ajaxShowMessage(PMA_messages.strDroppingColumn, false); - var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post')); + var params = getJSConfirmCommonParam(this, $this_anchor.getPostData()); params += '&ajax_page_request=1'; $.post(url, params, function (data) { if (typeof data !== 'undefined' && data.success === true) { @@ -269,7 +269,7 @@ AJAX.registerOnload('tbl_structure.js', function () { PMA_ajaxShowMessage(); AJAX.source = $this; - var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post')); + var params = getJSConfirmCommonParam(this, $this_anchor.getPostData()); params += '&ajax_page_request=1'; $.post(url, params, AJAX.responseHandler); }); // end $.PMA_confirm()