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 17, 2023
1 parent c49737d commit 420f31a
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 { joinUrlPaths } 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: joinUrlPaths(baseURL, 'show/:folderId/:viewAction/:fileId'),
component: AssetAdminRouter,
},
{
path: `${baseURL}/show/:folderId/:viewAction`,
path: joinUrlPaths(baseURL, 'show/:folderId/:viewAction'),
component: AssetAdminRouter,
},
{
path: `${baseURL}/show/:folderId`,
path: joinUrlPaths(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 { joinUrlPaths } 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 && joinUrlPaths(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 { joinUrlPaths } 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 = joinUrlPaths(base, `show/${folderId}/${CONSTANTS.ACTIONS.EDIT_FILE}/${fileId}`);
} else if (folderId) {
url = `${base}/show/${folderId}`;
url = joinUrlPaths(base, `show/${folderId}`);
} else {
url = `${base}/`;
url = base;
}

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

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

0 comments on commit 420f31a

Please sign in to comment.