Allow time tag to retain 'datetime' attribute in RCE #2532
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.
Overview
The CanvasSanitize configuration previously allowed the
<time>tag but stripped itsdatetimeattribute. This caused semantic information about dates/times to be lost when user content was sanitized. The proposed change updates CanvasSanitize to preserve thedatetimeattribute on the<time>tag. Corresponding RSpec coverage was added to ensure the attribute is retained exclusively on<time>. The TinyMCE config for the Rich Content Editor (RCE) was also updated to reflect this added support on the client side.Reasons for Proposal
Preserving Semantics
The
datetimeattribute is an important part of the<time>element in HTML, allowing dates/times to be machine-readable by assistive technologies, user agents, and scripts. Stripping the attribute undermines the element’s intended semantic use.Source: MDN
Accessibility
This change improves conformance with WCAG 2.2 SC 1.3.1 Info and Relationships (Level A) by preserving the semantic relationship between the visible date text and its machine-readable representation. This helps screen readers and other tools interpret temporal information more accurately.
For example, the following HTML snippet semantically uses the
<time>tag anddatetimeattribute to remove ambiguity for visually impaired users. It is a duration of 12 minutes and 30 seconds, not 12 hours and 30 minutes or a time of day.The ISO 8601 datetime string above maps to the following:
P = "period"
T = "time component"
12M = "12 minutes"
30S = "30 seconds"
Proposed Change
datetimeattribute only on<time>elements.datetimeon<time>.Test Plan
<time datetime="...">retains its attribute while other elements (<div datetime>,<span datetime>) have it stripped.