Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/editors/sharedComponents/TinyMceWidget/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,35 @@ describe('TinyMceEditor hooks', () => {
const content = module.setAssetToStaticUrl({ editorValue, lmsEndpointUrl });
expect(content).toEqual('<img src="/static/goku.img"/> <a href="/static/goku.img">testing link</a>');
});
it('returns content with updated jsinput html_file links', () => {
const editorValue = `<jsinput html_file="/${baseAssetUrl}@textlog.html" gradefn="getGrade"/>`;
const lmsEndpointUrl = getConfig().LMS_BASE_URL;
const content = module.setAssetToStaticUrl({ editorValue, lmsEndpointUrl });
expect(content).toEqual('<jsinput html_file="/static/textlog.html" gradefn="getGrade"/>');
});
it('returns content with updated jsinput html_file links when URL is absolute', () => {
const lmsEndpointUrl = getConfig().LMS_BASE_URL;
const editorValue = `<jsinput html_file="${lmsEndpointUrl}/${baseAssetUrl}@textlog.html" gradefn="getGrade"/>`;
const content = module.setAssetToStaticUrl({ editorValue, lmsEndpointUrl });
expect(content).toEqual('<jsinput html_file="/static/textlog.html" gradefn="getGrade"/>');
});
it('returns content with updated jsinput html_file links using encoded quotes', () => {
const editorValue = `<jsinput html_file=&quot;/${baseAssetUrl}@textlog.html&quot; gradefn=&quot;getGrade&quot;/>`;
const lmsEndpointUrl = getConfig().LMS_BASE_URL;
const content = module.setAssetToStaticUrl({ editorValue, lmsEndpointUrl });
expect(content).toEqual('<jsinput html_file=&quot;/static/textlog.html&quot; gradefn=&quot;getGrade&quot;/>');
});
Comment thread
Copilot marked this conversation as resolved.
it('does not strip the literal text "undefined" when lmsEndpointUrl is not provided', () => {
const editorValue = `<p>value may be undefined</p><img src="/${baseAssetUrl}@soME_ImagE_URl1"/>`;
const content = module.setAssetToStaticUrl({ editorValue });
expect(content).toEqual('<p>value may be undefined</p><img src="/static/soME_ImagE_URl1"/>');
});
it('returns content with updated href links using encoded quotes', () => {
const editorValue = `<a href=&quot;/${baseAssetUrl}@soMEImagEURl&quot;>testing link</a>`;
const lmsEndpointUrl = getConfig().LMS_BASE_URL;
const content = module.setAssetToStaticUrl({ editorValue, lmsEndpointUrl });
expect(content).toEqual('<a href=&quot;/static/soMEImagEURl&quot;>testing link</a>');
});
});

describe('editorConfig', () => {
Expand Down
9 changes: 6 additions & 3 deletions src/editors/sharedComponents/TinyMceWidget/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,13 @@ export const setAssetToStaticUrl = ({ editorValue, lmsEndpointUrl }) => {

// TODO: should probably move this to when the assets are being looped through in the off chance that
// some of the text in the editor contains the lmsEndpointUrl
const regExLmsEndpointUrl = RegExp(lmsEndpointUrl, 'g');
let content = editorValue.replace(regExLmsEndpointUrl, '');
let content = editorValue;
if (lmsEndpointUrl) {
const escapedLmsEndpointUrl = lmsEndpointUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
content = content.replace(RegExp(escapedLmsEndpointUrl, 'g'), '');
}

const assetSrcs = typeof content === 'string' ? content.split(/(src="|src=&quot;|href="|href=&quot)/g) : [];
const assetSrcs = typeof content === 'string' ? content.split(/(src="|src=&quot;|href="|href=&quot;|html_file="|html_file=&quot;)/g) : [];
Comment thread
djoseph-apphelix marked this conversation as resolved.
assetSrcs.filter(src => src.startsWith('/asset')).forEach(src => {
const nameFromEditorSrc = parseAssetName(src);
const portableUrl = getStaticUrl({ displayName: nameFromEditorSrc });
Expand Down
Loading