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 6222b8b
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 92 deletions.
Binary file removed client/dist/images/alert.gif
Binary file not shown.
Binary file removed client/dist/images/blue-folder-horizontal.png
Binary file not shown.
Binary file removed client/dist/images/loading.gif
Binary file not shown.
1 change: 0 additions & 1 deletion client/dist/js/SilverStripeNavigator.js

This file was deleted.

1 change: 0 additions & 1 deletion client/dist/js/TinyMCE_sslink-anchor.js

This file was deleted.

1 change: 0 additions & 1 deletion client/dist/js/TinyMCE_sslink-internal.js

This file was deleted.

48 changes: 0 additions & 48 deletions client/dist/js/bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion client/dist/styles/SilverStripeNavigator.css

This file was deleted.

1 change: 0 additions & 1 deletion client/dist/styles/bundle.css

This file was deleted.

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
16 changes: 8 additions & 8 deletions tests/php/Controllers/ModelAsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public function testRedirectsNestedRenamedPages()
$response = $this->get('newlevel1/level2');
$this->assertEquals($response->getStatusCode(), 301);
$this->assertEquals(
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2/'),
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2'),
$response->getHeader('Location')
);

// check third level URLSegment
$response = $this->get('newlevel1/newlevel2/level3');
$this->assertEquals($response->getStatusCode(), 301);
$this->assertEquals(
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2/newlevel3/'),
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2/newlevel3'),
$response->getHeader('Location')
);

Expand Down Expand Up @@ -153,10 +153,10 @@ public function testHeavilyNestedRenamedRedirectedPages()
$page5->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);

// Test that the redirect still works fine when trying to access the most nested page
$response = $this->get('oldurl/level2/level3/level4/level5/');
$response = $this->get('oldurl/level2/level3/level4/level5');
$this->assertEquals($response->getStatusCode(), 301);
$this->assertEquals(
Controller::join_links(Director::baseURL() . 'newurl/level2/level3/level4/level5/'),
Controller::join_links(Director::baseURL() . 'newurl/level2/level3/level4/level5'),
$response->getHeader('Location')
);
}
Expand All @@ -170,15 +170,15 @@ public function testRedirectionForPreNestedurlsBookmarks()
$response = $this->get('newlevel3');
$this->assertEquals(301, $response->getStatusCode());
$this->assertEquals(
Director::baseURL() . 'newlevel1/newlevel2/newlevel3/',
Director::baseURL() . 'newlevel1/newlevel2/newlevel3',
$response->getHeader("Location")
);

// So will the legacy ones
$response = $this->get('level3');
$this->assertEquals(301, $response->getStatusCode());
$this->assertEquals(
Director::baseURL() . 'newlevel1/newlevel2/newlevel3/',
Director::baseURL() . 'newlevel1/newlevel2/newlevel3',
$response->getHeader("Location")
);
}
Expand Down Expand Up @@ -214,10 +214,10 @@ public function testRedirectsNestedRenamedPagesWithGetParameters()
$this->generateNestedPagesFixture();

// check third level URLSegment
$response = $this->get('newlevel1/newlevel2/level3/?foo=bar&test=test');
$response = $this->get('newlevel1/newlevel2/level3?foo=bar&test=test');
$this->assertEquals($response->getStatusCode(), 301);
$this->assertEquals(
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2/newlevel3/', '?foo=bar&test=test'),
Controller::join_links(Director::baseURL() . 'newlevel1/newlevel2/newlevel3', '?foo=bar&test=test'),
$response->getHeader('Location')
);
}
Expand Down
Loading

0 comments on commit 6222b8b

Please sign in to comment.