Skip to content

Firefly III: a personal finances manager

Make sure redirect stuff works!

James Cole276372eaa67e
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index e90e4a4d37..db93758385 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -200,7 +200,7 @@ abstract class Controller extends BaseController
$parts = [];
parse_str($current['query'], $parts);
unset($parts['_from']);
- $from .= http_build_query($parts);
+ $from .= '?' . http_build_query($parts);
}
if (array_key_exists('fragment', $current) && '' !== $current['fragment']) {
$from .= '#'.$current['fragment'];
diff --git a/resources/assets/v3/js/pages/transactions/edit.js b/resources/assets/v3/js/pages/transactions/edit.js
index b20dd7aeda..38b5776052 100644
--- a/resources/assets/v3/js/pages/transactions/edit.js
+++ b/resources/assets/v3/js/pages/transactions/edit.js
@@ -369,6 +369,7 @@ let transactions = function () {
// if not, respond to user options:
this.showMessageOrRedirectUser();
}).catch((error) => {
+ console.log(error);
this.formStates.isSubmitting = false;
if (typeof error.response !== 'undefined') {
this.parseErrors(error.response.data);
diff --git a/resources/assets/v3/js/pages/transactions/shared/show-message-or-redirect.js b/resources/assets/v3/js/pages/transactions/shared/show-message-or-redirect.js
index 0aac9f93b0..244cd13a2f 100644
--- a/resources/assets/v3/js/pages/transactions/shared/show-message-or-redirect.js
+++ b/resources/assets/v3/js/pages/transactions/shared/show-message-or-redirect.js
@@ -57,20 +57,39 @@ export function showMessageOrRedirectUser() {
// the redirect also depends on the "from" in the query param, which is validated by Firefly III on the server side.
// get from parameter from query
const urlParams = new URLSearchParams(window.location.search);
- const from = urlParams.get('_from').toString();
+ let params = urlParams.get('_from');
+ // find parts
+ let parts = URL.parse(params, 'https://example.com/');
+ let from;
+ let separator = '?';
+ if('' === parts.search) {
+ from = urlParams.get('_from').toString();
+ }
+ if('' !== parts.search) {
+ let obj = new URLSearchParams(parts.search);
+ let pathName = parts.pathname; // we redirect here!
+ obj.delete('message');
+ obj.delete('transaction_group_id');
+ if(0 === obj.size) {
+ from = pathName;
+ }
+ if(obj.size > 0) {
+ separator = '&';
+ from = pathName + '?' + obj.toString();
+ }
+ }
// grab base href
let baseHref = document.querySelector('base').getAttribute('href');
baseHref = baseHref.substring(0, baseHref.length - 1);
+ let finalFrom = baseHref + from;
if ('' !== from) {
if('edit' === this.formBehaviour.formType) {
- console.log('Redirect to valid _from parameter: ' + baseHref + ' ' + from + ' ' + '?transaction_group_id=' + this.groupProperties.id + '&message=updated');
- window.location = baseHref + from + '?transaction_group_id=' + this.groupProperties.id + '&message=updated';
+ window.location = finalFrom + separator + 'transaction_group_id=' + this.groupProperties.id + '&message=updated';
return;
}
- console.log('Redirect to valid _from parameter: ' + baseHref + ' ' + from + ' ' + '?transaction_group_id=' + this.groupProperties.id + '&message=created');
- window.location = baseHref + from + '?transaction_group_id=' + this.groupProperties.id + '&message=created';
+ window.location = finalFrom + separator + 'transaction_group_id=' + this.groupProperties.id + '&message=created';
return;
}
if('edit' === this.formBehaviour.formType) {