Parse QTI items to rewrite them at publish instead of matching regexes - #6241
Open
rtibblesbot wants to merge 1 commit into
Open
rtibblesbot wants to merge 1 commit into
rtibblesbot wants to merge 1 commit into
Conversation
rtibblesbot
marked this pull request as ready for review
September 30, 2026 19:06
rtibblesbot
force-pushed
the
issue-6235-136df6
branch
from
September 30, 2026 19:13
805f224 to
41fc509
Compare
rtibblesbot
force-pushed
the
issue-6235-136df6
branch
3 times, most recently
from
October 1, 2026 15:27
ffdcad0 to
8a71d91
Compare
rtibbles
reviewed
Oct 2, 2026
rtibbles
left a comment
Member
There was a problem hiding this comment.
One question about continuing with a regex approach here.
| STUDIO_ATTRIBUTE_OR_QUOTED_VALUE_REGEX = re.compile( | ||
| r"""(?P<studio>\s+data-studio-[\w.-]+\s*=\s*(?:"[^"]*"|'[^']*'))|"[^"]*"|'[^']*'""" | ||
| ) | ||
| _WHITESPACE_REGEX = re.compile(r"\s*") |
Member
There was a problem hiding this comment.
Would it be better to just parse the XML at this point? Creating more and more sophisticated regex for all of these XML parsing operations just adds brittleness - how much does this really save us performance wise?
Contributor
Author
There was a problem hiding this comment.
Agreed — switched to parsing in 3c453e2. The savings were negligible: ~80µs per item for all three rewrites, each parsing separately.
- Searched
utils/assessment/for regexes and string ops that read XML structure; 4 places matched inqti/media.py, all now parse with lxml:set_qti_item_language,strip_studio_attributes,rewrite_qti_media_paths,rewrite_qti_sized_image_paths. - Regexes left only match attribute values (checksum filename, pixel length, srcset entries).
- Output is now re-serialized, so the author's formatting isn't kept byte-for-byte; tests assert on the parsed tree instead.
rtibblesbot
force-pushed
the
issue-6235-136df6
branch
3 times, most recently
from
October 2, 2026 23:27
20318f2 to
3c453e2
Compare
Contributor
Author
|
Outside this PR's scope — tracked in:
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly How was this generated?
|
rtibblesbot
force-pushed
the
issue-6235-136df6
branch
from
October 3, 2026 03:54
3c453e2 to
40c82a3
Compare
…egexes - set_qti_item_language finds the real root past prolog comments (learningequality#6235) and on a namespace-prefixed root (learningequality#6236). - rewrite_qti_media_paths rewrites a src written as an entity or character reference (learningequality#6240). - Published items are lxml's serialization, not the authored bytes; canonical XML is unchanged for valid items. Invalid XML now raises. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
rtibblesbot
force-pushed
the
issue-6235-136df6
branch
from
October 3, 2026 04:59
40c82a3 to
d9352ec
Compare
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.
Closes #6235
Refs #6236
Refs #6240
Publish-time QTI item rewrites in
utils/assessment/qti/media.pynow parse the item with lxml and edit the tree, replacing the regex text substitutions.set_qti_item_languagesetsxml:langon the real root, past prolog comments ([QTI] A QTI item with a comment quoting its root tag is published without the node's language #6235) and on a namespace-prefixed root (Published QTI item with a namespace-prefixed root gets no xml:lang #6236).rewrite_qti_media_pathsremaps asrcwritten as an entity or character reference ([QTI] A QTI item with an entity in a media src attribute is published with an unrewritten path #6240).rewrite_qti_sized_image_pathsandstrip_studio_attributesmove to the same parse/serialize path.🤖 Generated with Claude Code
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
🟡 Waiting for feedback
Last updated: 2026-10-03 05:07 UTC