Skip to content

Commit 6f603be

Browse files
committed
Normalize routes before comparison for editing redirect.
1 parent 79fac05 commit 6f603be

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

defaults/core/cms/providers/gitea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from '../../../generated/env.js';
2-
import { makeUrl } from '../url_checker.js';
2+
import { makeUrl, normalizeRoute } from '../url_checker.js';
33
import evaluateRoute from '../route_eval.js';
44

55
const repoUrl = makeUrl(env.cms.repo);
@@ -96,7 +96,7 @@ export async function commitGitea(commitList, shadowContent, action, encoding, u
9696
if (commitList.length === 1 && commitList[0].file.lastIndexOf('.json') > 0) {
9797
let evaluatedRoute = evaluateRoute(commitList[0]);
9898
// Redirect only if new route is being created
99-
if (evaluatedRoute !== location.pathname) {
99+
if (normalizeRoute(evaluatedRoute) !== normalizeRoute(location.pathname)) {
100100
history.pushState({
101101
isNew: true,
102102
route: evaluatedRoute

defaults/core/cms/providers/gitlab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from '../../../generated/env.js';
2-
import { makeUrl } from '../url_checker.js';
2+
import { makeUrl, normalizeRoute } from '../url_checker.js';
33
import evaluateRoute from '../route_eval.js';
44

55
const repoUrl = makeUrl(env.cms.repo);
@@ -70,7 +70,7 @@ export async function commitGitlab(commitList, shadowContent, action, encoding,
7070
if (commitList.length === 1 && commitList[0].file.lastIndexOf('.json') > 0) {
7171
let evaluatedRoute = evaluateRoute(commitList[0]);
7272
// Redirect only if new route is being created
73-
if (evaluatedRoute !== location.pathname) {
73+
if (normalizeRoute(evaluatedRoute) !== normalizeRoute(location.pathname)) {
7474
history.pushState({
7575
isNew: true,
7676
route: evaluatedRoute

defaults/core/cms/providers/local.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { env } from '../../../generated/env.js';
2+
import { normalizeRoute } from '../url_checker.js';
23
import evaluateRoute from '../route_eval.js';
34

45
export async function postLocal(commitList, shadowContent, action, encoding) {
@@ -28,7 +29,7 @@ export async function postLocal(commitList, shadowContent, action, encoding) {
2829
if (commitList.length === 1 && commitList[0].file.lastIndexOf('.json') > 0) {
2930
let evaluatedRoute = evaluateRoute(commitList[0]);
3031
// Redirect only if new route is being created
31-
if (evaluatedRoute !== location.pathname) {
32+
if (normalizeRoute(evaluatedRoute) !== normalizeRoute(location.pathname)) {
3233
history.pushState({
3334
isNew: true,
3435
route: evaluatedRoute

defaults/core/cms/url_checker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ export const makeUrl = string => {
44
} catch (_) {
55
return new URL("https://gitlab.com");
66
}
7+
}
8+
9+
export const normalizeRoute = route => {
10+
// Remove leading and trailing slashes
11+
return route.replace(/^\/+|\/+$/g, '');
712
}

0 commit comments

Comments
 (0)