This commit is contained in:
Nepomuk Leutschacher 2025-09-30 20:50:05 +02:00 committed by GitHub
commit 292b7b3e93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 23 deletions

View file

@ -311,11 +311,11 @@ jQuery.PrivateBin = (function($) {
/** /**
* cache for script location * cache for script location
* *
* @name Helper.baseUri * @name Helper.windowLocationBaseUri
* @private * @private
* @enum {string|null} * @enum {string|null}
*/ */
let baseUri = null; let windowLocationBaseUri = null;
/** /**
* converts a duration (in seconds) into human friendly approximation * converts a duration (in seconds) into human friendly approximation
@ -505,19 +505,32 @@ jQuery.PrivateBin = (function($) {
* get the current location (without search or hash part of the URL), * get the current location (without search or hash part of the URL),
* eg. https://example.com/path/?aaaa#bbbb --> https://example.com/path/ * eg. https://example.com/path/?aaaa#bbbb --> https://example.com/path/
* *
* @name Helper.baseUri * @name Helper.windowLocationBaseUri
* @function * @function
* @return {string} * @return {string}
*/ */
me.baseUri = function() me.windowLocationBaseUri = function()
{ {
// check for cached version // check for cached version
if (baseUri !== null) { if (windowLocationBaseUri !== null) {
return baseUri; return windowLocationBaseUri;
} }
baseUri = window.location.origin + window.location.pathname; windowLocationBaseUri = window.location.origin + window.location.pathname;
return baseUri; return windowLocationBaseUri;
};
/**
* get the basepath from config file,
* eg. https://privatebin.example.com/
*
* @name Helper.configBaseUri
* @function
* @return {string}
*/
me.configBaseUri = function()
{
return configBaseUri || me.windowLocationBaseUri();
}; };
/** /**
@ -627,7 +640,7 @@ jQuery.PrivateBin = (function($) {
*/ */
me.reset = function() me.reset = function()
{ {
baseUri = null; windowLocationBaseUri = null;
}; };
/** /**
@ -1446,7 +1459,7 @@ jQuery.PrivateBin = (function($) {
// reload data // reload data
ServerInteraction.prepare(); ServerInteraction.prepare();
ServerInteraction.setUrl(Helper.baseUri() + '?pasteid=' + me.getPasteId()); ServerInteraction.setUrl(Helper.windowLocationBaseUri() + '?pasteid=' + me.getPasteId());
ServerInteraction.setFailure(function (status, data) { ServerInteraction.setFailure(function (status, data) {
// revert loading status… // revert loading status…
@ -1624,7 +1637,7 @@ jQuery.PrivateBin = (function($) {
*/ */
function historyChange(event) function historyChange(event)
{ {
let currentLocation = Helper.baseUri(); let currentLocation = Helper.windowLocationBaseUri();
if (event.originalEvent.state === null && // no state object passed if (event.originalEvent.state === null && // no state object passed
event.target.location.href === currentLocation && // target location is home page event.target.location.href === currentLocation && // target location is home page
window.location.href === currentLocation // and we are not already on the home page window.location.href === currentLocation // and we are not already on the home page
@ -1644,7 +1657,7 @@ jQuery.PrivateBin = (function($) {
*/ */
me.reloadHome = function() me.reloadHome = function()
{ {
window.location.href = Helper.baseUri(); window.location.href = Helper.windowLocationBaseUri();
}; };
/** /**
@ -1743,7 +1756,7 @@ jQuery.PrivateBin = (function($) {
me.init = function() me.init = function()
{ {
// update link to home page // update link to home page
$('.reloadlink').prop('href', Helper.baseUri()); $('.reloadlink').prop('href', Helper.windowLocationBaseUri());
$(window).on('popstate', historyChange); $(window).on('popstate', historyChange);
}; };
@ -3925,7 +3938,7 @@ jQuery.PrivateBin = (function($) {
{type: 'raw'}, {type: 'raw'},
document.title, document.title,
// recreate document URL // recreate document URL
Helper.baseUri() + '?' + Model.getPasteId() + '#' + Helper.windowLocationBaseUri() + '?' + Model.getPasteId() + '#' +
CryptTool.base58encode(Model.getPasteKey()) CryptTool.base58encode(Model.getPasteKey())
); );
@ -4924,7 +4937,7 @@ jQuery.PrivateBin = (function($) {
// reset data // reset data
successFunc = null; successFunc = null;
failureFunc = null; failureFunc = null;
url = Helper.baseUri(); url = Helper.windowLocationBaseUri();
data = {}; data = {};
}; };
@ -5026,7 +5039,7 @@ jQuery.PrivateBin = (function($) {
Alert.hideMessages(); Alert.hideMessages();
// show notification // show notification
const baseUri = Helper.baseUri() + '?', const baseUri = Helper.configBaseUri() + '?',
url = baseUri + data.id + (TopNav.getBurnAfterReading() ? loadConfirmPrefix : '#') + CryptTool.base58encode(data.encryptionKey), url = baseUri + data.id + (TopNav.getBurnAfterReading() ? loadConfirmPrefix : '#') + CryptTool.base58encode(data.encryptionKey),
deleteUrl = baseUri + 'pasteid=' + data.id + '&deletetoken=' + data.deletetoken; deleteUrl = baseUri + 'pasteid=' + data.id + '&deletetoken=' + data.deletetoken;
PasteStatus.createPasteNotification(url, deleteUrl); PasteStatus.createPasteNotification(url, deleteUrl);
@ -5729,8 +5742,8 @@ jQuery.PrivateBin = (function($) {
Alert.hideLoading(); Alert.hideLoading();
// only push new state if we are coming from a different one // only push new state if we are coming from a different one
if (Helper.baseUri() != window.location) { if (Helper.windowLocationBaseUri() != window.location) {
history.pushState({type: 'create'}, document.title, Helper.baseUri()); history.pushState({type: 'create'}, document.title, Helper.windowLocationBaseUri());
} }
// clear discussion // clear discussion
@ -5777,7 +5790,7 @@ jQuery.PrivateBin = (function($) {
Model.getPasteData(function (data) { Model.getPasteData(function (data) {
ServerInteraction.prepare(); ServerInteraction.prepare();
ServerInteraction.setUrl(Helper.baseUri() + '?pasteid=' + Model.getPasteId()); ServerInteraction.setUrl(Helper.windowLocationBaseUri() + '?pasteid=' + Model.getPasteId());
ServerInteraction.setFailure(function (status, data) { ServerInteraction.setFailure(function (status, data) {
// revert loading status… // revert loading status…
@ -5819,7 +5832,7 @@ jQuery.PrivateBin = (function($) {
me.hideStatusMessages(); me.hideStatusMessages();
// erase the id and the key in url // erase the id and the key in url
history.pushState({type: 'clone'}, document.title, Helper.baseUri()); history.pushState({type: 'clone'}, document.title, Helper.windowLocationBaseUri());
if (AttachmentViewer.hasAttachment()) { if (AttachmentViewer.hasAttachment()) {
const attachments = AttachmentViewer.getAttachments(); const attachments = AttachmentViewer.getAttachments();

View file

@ -255,10 +255,10 @@ describe('Helper', function () {
); */ ); */
}); });
describe('baseUri', function () { describe('windowLocationBaseUri', function () {
this.timeout(30000); this.timeout(30000);
jsc.property( jsc.property(
'returns the URL without query & fragment', 'returns the window location URL without query & fragment',
common.jscSchemas(false), common.jscSchemas(false),
common.jscUrl(), common.jscUrl(),
function (schema, url) { function (schema, url) {
@ -269,7 +269,7 @@ describe('Helper', function () {
$.PrivateBin.Helper.reset(); $.PrivateBin.Helper.reset();
const expected = common.urlToString(url), const expected = common.urlToString(url),
clean = jsdom('', {url: fullUrl}), clean = jsdom('', {url: fullUrl}),
result = $.PrivateBin.Helper.baseUri(); result = $.PrivateBin.Helper.windowLocationBaseUri();
clean(); clean();
return expected === result; return expected === result;
} }

View file

@ -67,6 +67,7 @@ endif;
?> ?>
<?php $this->_scriptTag('js/purify-3.2.6.js', 'defer'); ?> <?php $this->_scriptTag('js/purify-3.2.6.js', 'defer'); ?>
<?php $this->_scriptTag('js/legacy.js', 'defer'); ?> <?php $this->_scriptTag('js/legacy.js', 'defer'); ?>
<script>const configBaseUri = '<?php echo I18n::encode($BASEPATH); ?>';</script>
<?php $this->_scriptTag('js/privatebin.js', 'defer'); ?> <?php $this->_scriptTag('js/privatebin.js', 'defer'); ?>
<!-- icon --> <!-- icon -->
<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" /> <link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />

View file

@ -51,6 +51,7 @@ endif;
?> ?>
<?php $this->_scriptTag('js/purify-3.2.6.js', 'defer'); ?> <?php $this->_scriptTag('js/purify-3.2.6.js', 'defer'); ?>
<?php $this->_scriptTag('js/legacy.js', 'defer'); ?> <?php $this->_scriptTag('js/legacy.js', 'defer'); ?>
<script>const baseUri = '<?php echo I18n::encode($BASEPATH); ?>';</script>
<?php $this->_scriptTag('js/privatebin.js', 'defer'); ?> <?php $this->_scriptTag('js/privatebin.js', 'defer'); ?>
<!-- icon --> <!-- icon -->
<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" /> <link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />