Skip to content

Commit fd52cec

Browse files
pulkit0555nrkruk
andauthored
fix: download site bundle correctly if site name has special chars (#262)
* fix: updated special chars in site name * fix: minor fix * fix: refactored code * chore: change test naming --------- Co-authored-by: Nicolas Kruk <[email protected]> Co-authored-by: Nicolas Kruk <[email protected]>
1 parent f6c0206 commit fd52cec

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/shared/experience/expSite.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export class ExperienceSite {
3737
this.org = org;
3838
this.siteDisplayName = siteName.trim();
3939
this.siteName = this.siteDisplayName.replace(' ', '_');
40+
// Replace any special characters in site name with underscore
41+
this.siteName = this.siteName.replace(/[^a-zA-Z0-9]/g, '_');
4042
}
4143

4244
/**

test/spec/expSite.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { expect } from 'chai';
8+
import { Connection, Org } from '@salesforce/core';
9+
import sinon from 'sinon';
10+
import { ExperienceSite } from '../../src/shared/experience/expSite.js';
11+
12+
describe('getRemoteMetadata', () => {
13+
it('should return remote metadata when it exists', async () => {
14+
const org = new Org();
15+
const siteName = 'site@with#special-chars';
16+
const experienceSite = new ExperienceSite(org, siteName);
17+
18+
// Create a mock Connection instance using sinon
19+
const mockConnection = sinon.createStubInstance(Connection);
20+
21+
// Configure the mock to return the desired result when calling query
22+
mockConnection.query.resolves({
23+
done: true,
24+
totalSize: 1,
25+
records: [
26+
{
27+
Name: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47',
28+
LastModifiedDate: '2024-11-12',
29+
},
30+
],
31+
});
32+
33+
// Replace the original connection with the mocked connection
34+
org.getConnection = () => mockConnection;
35+
36+
const remoteMetadata = await experienceSite.getRemoteMetadata();
37+
38+
// Check if the called query matches the expected pattern
39+
const calledQuery = mockConnection.query.args[0][0];
40+
const expectedPattern =
41+
/SELECT Name, LastModifiedDate FROM StaticResource WHERE Name LIKE 'MRT_experience_%_site_with_special_chars/;
42+
expect(calledQuery).to.match(expectedPattern);
43+
44+
expect(remoteMetadata).to.deep.equal({
45+
bundleName: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47',
46+
bundleLastModified: '2024-11-12',
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)