Skip to content

Commit d42fe29

Browse files
committed
fix: download site bundle correctly if site name has special chars
1 parent b9ca5a2 commit d42fe29

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/shared/experience/expSite.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,21 @@ export class ExperienceSite {
179179

180180
public async getRemoteMetadata(): Promise<SiteMetadata | undefined> {
181181
if (this.metadataCache.remoteMetadata) return this.metadataCache.remoteMetadata;
182+
// Check if there are special characters in the site name
183+
const siteNameHasSpacesOrSpecialChars = hasSpacesOrSpecialChars(this.siteName);
184+
const originalSiteName = this.siteName;
185+
if (siteNameHasSpacesOrSpecialChars) {
186+
const updatedSiteName = replaceSpacesAndSpecialChars(this.siteName);
187+
this.siteName = updatedSiteName;
188+
}
182189
const result = await this.org
183190
.getConnection()
184191
.query<{ Name: string; LastModifiedDate: string }>(
185192
`SELECT Name, LastModifiedDate FROM StaticResource WHERE Name LIKE 'MRT_experience_%_${this.siteName}'`
186193
);
194+
// Changing the site name back to original after fetching data from StaticResource so it may not break the flow elsewhere
195+
this.siteName = originalSiteName;
196+
187197
if (result.records.length === 0) {
188198
return undefined;
189199
}
@@ -356,3 +366,27 @@ function getSiteNameFromStaticResource(staticResourceName: string): string {
356366
}
357367
return parts.slice(4).join(' ');
358368
}
369+
370+
function replaceSpacesAndSpecialChars(value: string): string {
371+
// Replace any special characters with underscore
372+
value = value.replace(/[^a-zA-Z0-9]/g, '_');
373+
374+
// Replace spaces with underscore
375+
value = value.replace(/ /g, '_');
376+
377+
return value;
378+
}
379+
380+
function hasSpacesOrSpecialChars(value: string): boolean {
381+
// Check for spaces
382+
if (value.includes(' ')) {
383+
return true;
384+
}
385+
386+
// Check for special characters
387+
if (/[^\w]/.test(value)) {
388+
return true;
389+
}
390+
391+
return false;
392+
}

0 commit comments

Comments
 (0)