diff --git a/js/privatebin.js b/js/privatebin.js
index 08aea83..cf74733 100644
--- a/js/privatebin.js
+++ b/js/privatebin.js
@@ -743,13 +743,44 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
*/
me.getPasteId = function()
{
- if (id === null) {
- // Attention: This also returns the delete token inside of the ID, if it is specified
- id = (window.location.search.match(/[a-z0-9]{16}/) || [''])[0];
+ const idRegEx = /^[a-z0-9]{16}$/;
+ const idRegExFind = /[a-z0-9]{16}/;
- if (id === '') {
- throw 'no paste id given';
+ // return cached value
+ if (id !== null) {
+ return id;
+ }
+
+ // do use URL interface, if possible
+ if (window.URL && window.URL.prototype && ('searchParams' in window.URL.prototype)) {
+ try {
+ const url = new URL(window.location);
+
+ for (const param of url.searchParams) {
+ const key = param[0];
+ const value = param[1];
+
+ if (value === '' && idRegEx.test(key)) {
+ // safe, as the whole regex is matched
+ id = key;
+ return id;
+ }
+ }
+ } catch (e) {
+ // fallback below
+ console.error('URL interface not properly supported, error:', e);
}
+ } else {
+ console.warn('URL interface appears not to be supported in this browser.');
+ }
+
+ // fallback to simple RegEx
+ console.warn('fallback to simple RegEx search');
+ // Attention: This also returns the delete token inside of the ID, if it is specified
+ id = (window.location.search.match(idRegExFind) || [''])[0];
+
+ if (id === '') {
+ throw 'no paste id given';
}
return id;
diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php
index 64bebc4..fdc1b51 100644
--- a/tpl/bootstrap.php
+++ b/tpl/bootstrap.php
@@ -76,7 +76,7 @@ if ($MARKDOWN):
endif;
?>
-
+
diff --git a/tpl/page.php b/tpl/page.php
index 685a207..8d87ea6 100644
--- a/tpl/page.php
+++ b/tpl/page.php
@@ -54,7 +54,7 @@ if ($MARKDOWN):
endif;
?>
-
+