Skip to content

Commit 2ee4dfa

Browse files
authored
sanitize_html: append rel attributes instead of overriding (#223)
1 parent 4841428 commit 2ee4dfa

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

sanitize_html/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## v2.0.0-dev
1+
## v2.1.0
22
* Remove custom HTML rendering logic in favor of logic from `package:html`.
33
* Added `topics` to `pubspec.yaml`.
4+
* `rel` attributes added through `addLinkRel` are appended to existing ones.
45

56
## v2.0.0
67
* Migrate to null safety.

sanitize_html/lib/src/sane_html_validator.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ class SaneHtmlValidator {
249249
if (href != null && addLinkRel != null) {
250250
final rels = addLinkRel!(href);
251251
if (rels != null && rels.isNotEmpty) {
252-
node.attributes['rel'] = rels.join(' ');
252+
final currentRel = node.attributes['rel'] ?? '';
253+
final allRels = <String>{
254+
...currentRel.split(' ').where((e) => e.isNotEmpty),
255+
...rels,
256+
};
257+
node.attributes['rel'] = allRels.join(' ');
253258
}
254259
}
255260
}

sanitize_html/pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sanitize_html
2-
version: 2.0.0-dev
2+
version: 2.1.0
33
description: >-
44
Function for sanitizing HTML to prevent XSS by restrict elements and
55
attributes to a safe subset of allowed values.
@@ -14,7 +14,7 @@ dependencies:
1414
meta: ^1.1.7
1515
dev_dependencies:
1616
test: ^1.5.1
17-
lints: ^1.0.0
18-
markdown: ^4.0.0
17+
lints: ^2.0.0
18+
markdown: ^7.1.1
1919
environment:
20-
sdk: '>=2.12.0 <3.0.0'
20+
sdk: '>=2.12.0 <4.0.0'

0 commit comments

Comments
 (0)