Skip to content

Commit 5d0e417

Browse files
fix(lib-util): treat root-relative media paths as absolute (decaporg#7650)
* fix(lib-util): treat root-relative media paths as absolute * fix(core): normalize public folder slashes --------- Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com>
1 parent 826a300 commit 5d0e417

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/decap-cms-core/src/reducers/entries.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ let slug: string;
7878

7979
const storageSortKey = 'decap-cms.entries.sort';
8080
const viewStyleKey = 'decap-cms.entries.viewStyle';
81+
82+
function normalizeDoubleSlashes(path: string) {
83+
if (!path) {
84+
return path;
85+
}
86+
87+
return path.replace(/([^:]\/)\/+/g, '$1');
88+
}
8189
type StorageSortObject = SortObject & { index: number };
8290
type StorageSort = { [collection: string]: { [key: string]: StorageSortObject } };
8391

@@ -785,12 +793,14 @@ export function selectMediaFilePublicPath(
785793
}
786794

787795
const name = 'public_folder';
788-
let publicFolder = config[name]!;
796+
let publicFolder = normalizeDoubleSlashes(config[name]!);
789797

790798
const customFolder = hasCustomFolder(name, collection, entryMap?.get('slug'), field);
791799

792800
if (customFolder) {
793-
publicFolder = evaluateFolder(name, config, collection!, entryMap, field);
801+
publicFolder = normalizeDoubleSlashes(
802+
evaluateFolder(name, config, collection!, entryMap, field),
803+
);
794804
}
795805

796806
if (isAbsolutePath(publicFolder)) {

packages/decap-cms-lib-util/src/path.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const absolutePath = new RegExp('^(?:[a-z]+:)?//', 'i');
1+
const absolutePath = new RegExp('^(?:[a-z]+:)?//|^/', 'i');
22

33
function normalizePath(path: string) {
44
return path.replace(/[\\/]+/g, '/');
55
}
66

77
export function isAbsolutePath(path: string) {
8-
return absolutePath.test(path);
8+
const result = absolutePath.test(path);
9+
return result;
910
}
1011

1112
/**

0 commit comments

Comments
 (0)