Skip to content

Commit

Permalink
API Normalise trailing slashes in links
Browse files Browse the repository at this point in the history
  • Loading branch information
xini authored and GuySartorelli committed Jan 17, 2023
1 parent 50cefa6 commit 8b15a90
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/SilverStripeNavigator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-anchor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-internal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/src/legacy/CMSMain.Tree.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'jquery';
import i18n from 'i18n';
import reactConfirm from 'reactstrap-confirm';
import { joinUrlPaths } from 'lib/urls';

$.entwine('ss.tree', function($) {
$('.cms-tree').entwine({
Expand Down Expand Up @@ -45,7 +46,7 @@ $.entwine('ss.tree', function($) {
});

const baseUrl = $('base').attr('href') || ''; // Edge17 and IE11 require absolute paths
window.location.assign(baseUrl + urlWithParams);
window.location.assign(joinUrlPaths(baseUrl, urlWithParams));
},

getTreeConfig: function() {
Expand Down
3 changes: 2 additions & 1 deletion client/src/legacy/CMSMain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import $ from 'jquery';
import { joinUrlPaths } from 'lib/urls';

/**
* Behaviour for the CMS Content Toolbar.
Expand Down Expand Up @@ -81,7 +82,7 @@ $.entwine('ss', function ($) {
localStorage.setItem('ss.pages-view-type', viewType);
if(isContentViewInSidebar && viewType === VIEW_TYPE_LIST) {
const baseUrl = $('base').attr('href') || ''; // Edge17 and IE11 need absolute path
window.location.assign(baseUrl + $contentView.data('url-listviewroot'));
window.location.assign(joinUrlPaths(baseUrl, $contentView.data('url-listviewroot')));

return;
}
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/ModelAsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function handleRequest(HTTPRequest $request): HTTPResponse
// If the database has not yet been created, redirect to the build page.
/** @skipUpgrade */
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
$this->getResponse()->redirect(Controller::join_links(Director::absoluteBaseURL(), 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)));
$this->popCurrent();

return $this->getResponse();
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/OldPageRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function find_old_page($params, $parent = null, $redirect = false)
// No valid page found.
if ($redirect) {
// If we had some redirect to be done, lets do it. imagine /foo/action -> /bar/action, we still want this redirect to happen if action isn't a page
return $page->Link() . implode('/', $params);
return Controller::join_links($page->Link(), implode('/', $params));
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion code/Forms/SiteTreeURLSegmentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function setURLPrefix($url)
*/
public function getURLPrefix()
{
return $this->urlPrefix;
return rtrim($this->urlPrefix ?? '', '/') . '/';
}

public function getURLSuffix()
Expand Down
2 changes: 1 addition & 1 deletion code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public function RelativeLink($action = null)
$action = null;
}

$link = Controller::join_links($base, '/', $action);
$link = Controller::join_links($base, $action);

$this->extend('updateRelativeLink', $link, $base, $action);

Expand Down
Loading

0 comments on commit 8b15a90

Please sign in to comment.