fix: contract jsinput html_file asset URLs to /static/ on save (LP-704)#106
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an authoring-time portability regression where JSInput html_file asset URLs (expanded to course-pinned /asset-v1:... references by the Studio GET API) were being persisted on save instead of being contracted back to portable /static/<name> URLs.
Changes:
- Extend
setAssetToStaticUrl’s attribute-splitting logic to recognize JSInputhtml_file="..."andhtml_file="..."so those URLs are contracted on save. - Add unit tests to validate
html_filecontraction behavior for both plain-quoted and"-encoded attributes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/editors/sharedComponents/TinyMceWidget/hooks.ts |
Updates the URL contraction splitter to include JSInput html_file attributes. |
src/editors/sharedComponents/TinyMceWidget/hooks.test.js |
Adds tests asserting JSInput html_file asset URLs are rewritten to /static/... on save. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let content = editorValue.replace(regExLmsEndpointUrl, ''); | ||
|
|
||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href=")/g) : []; | ||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href="|html_file="|html_file=")/g) : []; |
djoseph-apphelix
force-pushed
the
djoseph/LP-704
branch
from
July 7, 2026 13:39
1b12a10 to
5207a40
Compare
Comment on lines
+513
to
+516
| const regExLmsEndpointUrl = RegExp(lmsEndpointUrl, 'g'); | ||
| let content = editorValue.replace(regExLmsEndpointUrl, ''); | ||
|
|
||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href=")/g) : []; | ||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href="|html_file="|html_file=")/g) : []; |
Comment on lines
+513
to
+516
| const regExLmsEndpointUrl = RegExp(lmsEndpointUrl, 'g'); | ||
| let content = editorValue.replace(regExLmsEndpointUrl, ''); | ||
|
|
||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href=")/g) : []; | ||
| const assetSrcs = typeof content === 'string' ? content.split(/(src="|src="|href="|href="|html_file="|html_file=")/g) : []; |
djoseph-apphelix
force-pushed
the
djoseph/LP-704
branch
from
July 7, 2026 13:45
5207a40 to
da13cf5
Compare
abhalsod-sonata
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes LP-704 (frontend layer): the editor bakes course-pinned absolute asset URLs into JSInput problems on save, breaking them after a course re-run or export/import.
Studio's GET API expands portable
/static/<name>references into absoluteasset-v1:<Org>+<Course>+<Run>+...URLs pinned to the current course, and the save path persists whatever the editor posts.setAssetToStaticUrl(src/editors/sharedComponents/TinyMceWidget/hooks.ts) is the editor's contraction step, but its split regex only recognizessrc=andhref=attributes — JSInput'shtml_file=passes through untouched, so the expanded absolute URL gets saved. After a re-run, the URL still points at the original course and the problem breaks (this is the failure Harvard reported).The fix
html_file="/html_file="to the attribute-splitting regex insetAssetToStaticUrl, so JSInput asset references are contracted back to/static/<name>on save like image/link references already are.href="token, which was missing its trailing;:"is the complete HTML entity, so the token matched one character short, left a leading;on the next split segment, and"-encodedhrefasset URLs were never contracted.lmsEndpointUrlhost-stripping regex: some call sites (RawEditor,TextEditor) invokesetAssetToStaticUrlwithoutlmsEndpointUrl, which previously built/undefined/gand silently deleted the literal text "undefined" from saved content; the URL's regex metacharacters (.) are now escaped as well.Testing
hooks.test.js: a JSInputhtml_filewith an expanded asset URL is rewritten to/static/<name>on save (plain-quoted,"-encoded, and LMS-absolutehttps://<lms>/asset-v1:...forms); a"-encodedhrefasset URL is likewise contracted; and content containing the literal text "undefined" survives a save withoutlmsEndpointUrl.html_file.Screenshots
Before
After
Companion server-side fix: edx/edx-platform#377