Skip to content

Commit 3847d2f

Browse files
committed
feat: add option to validate asset URLs before replacement in TinyMCE content
1 parent f2e5ff3 commit 3847d2f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/editors/sharedComponents/TinyMceWidget/hooks.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const replaceStaticWithAsset = ({
8585
learningContextId,
8686
editorType,
8787
lmsEndpointUrl,
88+
validateAssetUrl = true,
8889
}) => {
8990
let content = initialContent;
9091
let hasChanges = false;
@@ -126,8 +127,10 @@ export const replaceStaticWithAsset = ({
126127

127128
// check if the asset exists on the server before replacing
128129
try {
129-
await getAuthenticatedHttpClient()
130-
.get(staticFullUrl);
130+
if (validateAssetUrl) {
131+
await getAuthenticatedHttpClient()
132+
.get(staticFullUrl);
133+
}
131134
content = currentContent.replace(currentSrc, staticFullUrl);
132135
hasChanges = true;
133136
} catch (e) {

src/editors/sharedComponents/TinyMceWidget/hooks.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ describe('TinyMceEditor hooks', () => {
194194
const lmsEndpointUrl = getConfig().LMS_BASE_URL;
195195
it('returns updated src for text editor to update content', () => {
196196
const expected = `<img src="/${baseAssetUrl}@soMEImagEURl1.jpeg"/><a href="/${baseAssetUrl}@test.pdf">test</a><img src="/${baseAssetUrl}@correct.png" /><img src="/${baseAssetUrl}@correct.png" />`;
197-
const actual = module.replaceStaticWithAsset({ initialContent, learningContextId });
197+
const actual = module.replaceStaticWithAsset({
198+
initialContent,
199+
learningContextId,
200+
validateAssetUrl: false,
201+
202+
});
198203
expect(actual).toEqual(expected);
199204
});
200205
it('returns updated src with absolute url for expandable editor to update content', () => {
@@ -205,6 +210,7 @@ describe('TinyMceEditor hooks', () => {
205210
editorType,
206211
lmsEndpointUrl,
207212
learningContextId,
213+
validateAssetUrl: false,
208214
});
209215
expect(actual).toEqual(expected);
210216
});

0 commit comments

Comments
 (0)