Repository navigation
Conversation
paulbalandan
requested changes
Nov 13, 2026
michalsn
requested changes
Nov 13, 2026
gr8man
force-pushed
the
fix/html-helper-media-escaping
branch
from
November 13, 2026 20:45
675995f to
3db4058
Compare
michalsn
requested changes
Nov 15, 2026
michalsn
left a comment
Member
There was a problem hiding this comment.
Looks good to me. I've left a wording suggestion for the changelog. Please also update the PR title to reflect the final scope and clarify that source() is called by the caller, not internally by video() or audio().
Please also avoid manually wrapping paragraphs in the PR description.
gr8man
force-pushed
the
fix/html-helper-media-escaping
branch
from
November 15, 2026 15:08
f369057 to
4b498bb
Compare
…a tags The `video()`, `audio()`, `_media()`, `source()`, `track()`, `object()`, `param()` and `embed()` helpers concatenated their arguments straight into double-quoted HTML attributes. A value containing a double quote - a `src`, `type`, `kind`, `label` or `name` that comes from a database column or a request parameter, for instance - could therefore close the attribute and inject arbitrary ones, such as `onerror`, into the generated markup. Attribute values now go through a new `_esc_attr()` helper that applies `htmlspecialchars()` with `ENT_QUOTES | ENT_SUBSTITUTE`, so both quote styles, `<`, `>` and `&` are encoded while ordinary URLs stay readable. `ENT_SUBSTITUTE` keeps invalid UTF-8 from turning the whole value into an empty string. The `$unsupportedMessage` fallback text of `video()`, `audio()` and `_media()` was emitted verbatim as well, so markup passed as the fallback message was rendered as HTML. It is now escaped with `esc($message, 'html')` and displayed as plain text. Regression tests cover each affected helper, including the alternative `ENT_SUBSTITUTE` behaviour.
GitHub-only alert `> [!NOTE]` does not render in MkDocs; use the admonition syntax from contributing/documentation.md, and document that `$unsupportedMessage`, `$attributes`, `$tracks` and `$params` are inserted as raw HTML.
Cover `&` encoding through `video()` and through `video()` -> `source()` -> `_media()`, so a missing or a duplicated `esc()` fails the test.
gr8man
force-pushed
the
fix/html-helper-media-escaping
branch
from
November 15, 2026 20:20
4b498bb to
39b9729
Compare
This branch has not been deployed
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
The
video(),audio(),_media(),source(),track(),object(),param()andembed()helpers concatenated their arguments directly into double-quoted HTML attributes. Any value containing a double quote closed the attribute it was placed in, so caller-controlled data — asrc,type,kind,label,srclang,nameorvaluecoming from a database column or a request parameter — could inject arbitrary attributes such asonerrorinto the generated tag.Attribute values now go through the existing
esc($value, 'html')helper, which applieshtmlspecialchars()withENT_QUOTES | ENT_SUBSTITUTE. Both quote styles,<,>and&are encoded while ordinary URLs stay readable, and invalid UTF-8 is substituted instead of emptying the value.Every value is escaped exactly once.
source(),track(),param()andembed()escape their own attribute values before returning their markup. In the array form ofvideo()andaudio(), the caller passes the strings returned bysource()andtrack(), and_media()inserts them as raw HTML without escaping them again.The
$unsupportedMessage,$attributes,$tracksand$paramsparameters are intentionally left as raw HTML.$unsupportedMessagetherefore keeps supporting fallback markup such as download links, and callers are responsible for not passing unescaped user input in these parameters. The user guide now documents this behaviour with a MkDocs note.Output for input without special characters is unchanged, which the existing tests assert. Regression tests cover every affected helper, including single escaping of
&.Checklist: