Skip to content

Commit 94ca66c

Browse files
committed
events,html: support for unstable MSC4286
See: matrix-org/matrix-spec-proposals#4286
1 parent 38d471d commit 94ca66c

File tree

9 files changed

+61
-0
lines changed

9 files changed

+61
-0
lines changed

crates/ruma-events/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Improvements:
3232

3333
- Add support for ThumbHash as an alternative to BlurHash for MSC2448 in
3434
`ImageInfo` and `VideoInfo`.
35+
- Add unstable support for the `data-mx-payment-details` attribute for spans, according to MSC4286.
3536

3637
# 0.30.2
3738

crates/ruma-events/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ unstable-msc4171 = []
4747
unstable-msc4230 = []
4848
unstable-msc4274 = []
4949
unstable-msc4278 = []
50+
unstable-msc4286 = []
5051
unstable-pdu = []
5152

5253
# Allow some mandatory fields to be missing, defaulting them to an empty string

crates/ruma-html/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# [unreleased]
22

3+
Improvements:
4+
5+
- Add unstable support for the `data-mx-payment-details` attribute for spans, according to MSC4286.
6+
37
# 0.4.0
48

59
Upgrade `ruma-common` to 0.15.0.

crates/ruma-html/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ all-features = true
1515

1616
[features]
1717
matrix = ["dep:ruma-common"]
18+
unstable-msc4286 = []
1819

1920
[dependencies]
2021
as_variant = { workspace = true }

crates/ruma-html/src/html/matrix.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,14 @@ pub struct SpanData {
607607
/// [mathematical message]: https://spec.matrix.org/latest/client-server-api/#mathematical-messages
608608
/// [LaTeX]: https://www.latex-project.org/
609609
pub maths: Option<StrTendril>,
610+
611+
/// `data-mx-external-payment-details`, unstable feature from MSC4186.
612+
///
613+
/// This uses the unstable prefix in [MSC4286].
614+
///
615+
/// [MSC4286]: https://github.com/matrix-org/matrix-spec-proposals/pull/4286
616+
#[cfg(feature = "unstable-msc4286")]
617+
pub external_payment_details: Option<StrTendril>,
610618
}
611619

612620
impl SpanData {
@@ -640,6 +648,10 @@ impl SpanData {
640648
b"data-mx-maths" => {
641649
data.maths = Some(attr.value.clone());
642650
}
651+
#[cfg(feature = "unstable-msc4286")]
652+
b"data-msc4286-external-payment-details" => {
653+
data.external_payment_details = Some(attr.value.clone());
654+
}
643655
_ => {
644656
remaining_attrs.insert(attr.clone());
645657
}

crates/ruma-html/src/sanitizer_config/clean.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ static ALLOWED_ATTRIBUTES_STRICT: Map<&str, &Set<&str>> = phf_map! {
3030
"code" => &ALLOWED_ATTRIBUTES_CODE_STRICT,
3131
"div" => &ALLOWED_ATTRIBUTES_DIV_STRICT,
3232
};
33+
34+
#[cfg(not(feature = "unstable-msc4286"))]
3335
static ALLOWED_ATTRIBUTES_SPAN_STRICT: Set<&str> =
3436
phf_set! { "data-mx-bg-color", "data-mx-color", "data-mx-spoiler", "data-mx-maths" };
37+
38+
#[cfg(feature = "unstable-msc4286")]
39+
static ALLOWED_ATTRIBUTES_SPAN_STRICT: Set<&str> =
40+
phf_set! { "data-mx-bg-color", "data-mx-color", "data-mx-spoiler", "data-mx-maths", "data-msc4286-external-payment-details" };
41+
3542
static ALLOWED_ATTRIBUTES_A_STRICT: Set<&str> = phf_set! { "target", "href" };
3643
static ALLOWED_ATTRIBUTES_IMG_STRICT: Set<&str> =
3744
phf_set! { "width", "height", "alt", "title", "src" };

crates/ruma-html/tests/it/html/matrix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn span_attributes() {
6161
data-mx-bg-color=\"#ff0000\" \
6262
data-mx-spoiler \
6363
data-mx-spoiler=\"This is a spoiler\"\
64+
data-msc4286-external-payment-details=\"foo\"\
6465
>\
6566
Hidden and colored\
6667
</span>\
@@ -78,6 +79,9 @@ fn span_attributes() {
7879
// Uses the first spoiler attribute, the second is dropped.
7980
assert!(span.spoiler.unwrap().is_empty());
8081

82+
#[cfg(feature = "unstable-msc4286")]
83+
assert_eq!(span.external_payment_details.unwrap().as_ref(), "foo");
84+
8185
assert!(span_element.attrs.is_empty());
8286
}
8387

crates/ruma-html/tests/it/html/sanitize.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,32 @@ fn remove_classes() {
846846
"
847847
);
848848
}
849+
850+
#[cfg(feature = "unstable-msc4286")]
851+
#[test]
852+
fn strict_mode_external_payment_details() {
853+
let config = SanitizerConfig::strict().remove_reply_fallback();
854+
let html = Html::parse(
855+
"\
856+
<p>\
857+
some text here\
858+
<span data-msc4286-external-payment-details=\"foo\">\
859+
<a href=\"https://example.com\">link</a>\
860+
</span>\
861+
</p>\
862+
",
863+
);
864+
html.sanitize_with(&config);
865+
866+
assert_eq!(
867+
html.to_string(),
868+
"\
869+
<p>\
870+
some text here\
871+
<span data-msc4286-external-payment-details=\"foo\">\
872+
<a href=\"https://example.com\">link</a>\
873+
</span>\
874+
</p>\
875+
",
876+
);
877+
}

crates/ruma/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ unstable-msc4203 = ["ruma-appservice-api?/unstable-msc4203"]
192192
unstable-msc4230 = ["ruma-events?/unstable-msc4230"]
193193
unstable-msc4274 = ["ruma-events?/unstable-msc4274"]
194194
unstable-msc4278 = ["ruma-events?/unstable-msc4278"]
195+
unstable-msc4286 = ["ruma-events?/unstable-msc4286", "ruma-html?/unstable-msc4286"]
195196
unstable-pdu = ["ruma-events?/unstable-pdu"]
196197

197198
# Private features, only used in test / benchmarking code
@@ -245,6 +246,7 @@ __unstable-mscs = [
245246
"unstable-msc4230",
246247
"unstable-msc4274",
247248
"unstable-msc4278",
249+
"unstable-msc4286",
248250
]
249251
__ci = [
250252
"full",

0 commit comments

Comments
 (0)