Skip to content

Commit

Permalink
ENH Allow URLs without trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 12, 2023
1 parent c49737d commit 9038589
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_ssembed.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/js/TinyMCE_sslink-file.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/js/TinyMCE_ssmedia.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions client/src/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import applyTransform from 'boot/applyTransform';
import registerReducers from 'boot/registerReducers';
import registerComponents from 'boot/registerComponents';
import registerQueries from 'boot/registerQueries';
import { joinLinks } from 'lib/urls';

document.addEventListener('DOMContentLoaded', () => {
registerComponents();
Expand All @@ -18,19 +19,19 @@ document.addEventListener('DOMContentLoaded', () => {
path: '/',
routes: [
{
path: `${baseURL}/show/:folderId/:viewAction/:fileId`,
path: joinLinks(baseURL, 'show/:folderId/:viewAction/:fileId'),
component: AssetAdminRouter,
},
{
path: `${baseURL}/show/:folderId/:viewAction`,
path: joinLinks(baseURL, 'show/:folderId/:viewAction'),
component: AssetAdminRouter,
},
{
path: `${baseURL}/show/:folderId`,
path: joinLinks(baseURL, 'show/:folderId'),
component: AssetAdminRouter,
},
{
path: `${baseURL}`,
path: baseURL,
component: AssetAdminRouter,
},
],
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/InsertEmbedModal/InsertEmbedModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import FormBuilderModal from 'components/FormBuilderModal/FormBuilderModal';
import * as schemaActions from 'state/schema/SchemaActions';
import PropTypes from 'prop-types';
import { joinLinks } from 'lib/urls';

const sectionConfigKey = 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin';

Expand Down Expand Up @@ -174,7 +175,7 @@ function mapStateToProps(state, ownProps) {
const targetUrl = ownProps.fileAttributes ? ownProps.fileAttributes.Url : '';
const baseEditUrl = sectionConfig.form.remoteEditForm.schemaUrl;

const editUrl = targetUrl && `${baseEditUrl}/?embedurl=${encodeURIComponent(targetUrl)}`;
const editUrl = targetUrl && joinLinks(baseEditUrl, `/?embedurl=${encodeURIComponent(targetUrl)}`);
const createUrl = sectionConfig.form.remoteCreateForm.schemaUrl;

const schemaUrl = editUrl || createUrl;
Expand Down
9 changes: 5 additions & 4 deletions client/src/containers/AssetAdmin/AssetAdminRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { decodeQuery } from 'lib/DataFormat';
import qs from 'qs';
import CONSTANTS from 'constants/index';
import configShape from 'lib/configShape';
import { joinLinks } from 'lib/urls';

const sectionConfigKey = 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin';

Expand All @@ -29,15 +30,15 @@ function buildUrl({ base, folderId, fileId, query, action }) {

let url = null;
if (fileId) {
url = `${base}/show/${folderId}/${CONSTANTS.ACTIONS.EDIT_FILE}/${fileId}`;
url = joinLinks(base, `show/${folderId}/${CONSTANTS.ACTIONS.EDIT_FILE}/${fileId}`);
} else if (folderId) {
url = `${base}/show/${folderId}`;
url = joinLinks(base, `show/${folderId}`);
} else {
url = `${base}/`;
url = base;
}

if (action === CONSTANTS.ACTIONS.CREATE_FOLDER) {
url = `${base}/show/${folderId || 0}/${action}`;
url = joinLinks(base, `show/${folderId || 0}/${action}`);
}

const hasQuery = query && Object.keys(query).length > 0;
Expand Down

0 comments on commit 9038589

Please sign in to comment.