From 47646e056b27aafcc1b300402cfd027b93315f19 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 18 Aug 2016 15:09:58 +0200 Subject: [PATCH] fixing urlshortening regression caused by CSP introduction, resolves #10 --- js/privatebin.js | 32 +++++++++++++++++++++++++++----- tpl/bootstrap-compact.php | 2 +- tpl/bootstrap-dark-page.php | 2 +- tpl/bootstrap-dark.php | 2 +- tpl/bootstrap-page.php | 2 +- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index ad294af..cc2e60c 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -536,6 +536,16 @@ $(function() { */ headers: {'X-Requested-With': 'JSONHttpRequest'}, + /** + * URL shortners create address + */ + shortenerUrl: '', + + /** + * URL of newly created paste + */ + createdPasteUrl: '', + /** * Get the current script location (without search or hash part of the URL). * eg. http://server.com/zero/?aaaa#bbbb --> http://server.com/zero/ @@ -1077,6 +1087,10 @@ $(function() { url, url ) + privatebin.shortenUrl(url) ); + var shortenButton = $('#shortenbutton'); + if (shortenButton) { + shortenButton.click($.proxy(privatebin.sendToShortener, privatebin)); + } $('#deletelink').html('' + i18n._('Delete data') + ''); privatebin.pasteResult.removeClass('hidden'); // We pre-select the link so that the user only has to [Ctrl]+[c] the link. @@ -1110,11 +1124,8 @@ $(function() { { var shortenerHtml = $('#shortenbutton'); if (shortenerHtml) { - var shortener = shortenerHtml.data('shortener'); - shortenerHtml.attr( - 'onclick', - "window.location.href = '" + shortener + encodeURIComponent(url) + "';" - ); + this.shortenerUrl = shortenerHtml.data('shortener'); + this.createdPasteUrl = url; return ' ' + $('
').append(shortenerHtml.clone()).html(); } return ''; @@ -1219,6 +1230,17 @@ $(function() { } }, + /** + * Forward to URL shortener. + * + * @param Event event + */ + sendToShortener: function(event) + { + event.preventDefault(); + window.location.href = this.shortenerUrl + encodeURIComponent(this.createdPasteUrl); + }, + /** * Reload the page. * diff --git a/tpl/bootstrap-compact.php b/tpl/bootstrap-compact.php index 1df48e4..e1a6129 100644 --- a/tpl/bootstrap-compact.php +++ b/tpl/bootstrap-compact.php @@ -51,7 +51,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-dark-page.php b/tpl/bootstrap-dark-page.php index f6c9416..3582c83 100644 --- a/tpl/bootstrap-dark-page.php +++ b/tpl/bootstrap-dark-page.php @@ -51,7 +51,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-dark.php b/tpl/bootstrap-dark.php index fbe1b55..b91e812 100644 --- a/tpl/bootstrap-dark.php +++ b/tpl/bootstrap-dark.php @@ -51,7 +51,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-page.php b/tpl/bootstrap-page.php index cbbc242..9bc03a6 100644 --- a/tpl/bootstrap-page.php +++ b/tpl/bootstrap-page.php @@ -51,7 +51,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index e7c947c..840cc55 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -51,7 +51,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 2de6103..72ba25b 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -46,7 +46,7 @@ if ($MARKDOWN): - +