Skip to content

Commit

Permalink
sanitize_html: append rel attributes instead of overriding (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Sep 28, 2023
1 parent 4841428 commit 2ee4dfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion sanitize_html/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v2.0.0-dev
## v2.1.0
* Remove custom HTML rendering logic in favor of logic from `package:html`.
* Added `topics` to `pubspec.yaml`.
* `rel` attributes added through `addLinkRel` are appended to existing ones.

## v2.0.0
* Migrate to null safety.
Expand Down
7 changes: 6 additions & 1 deletion sanitize_html/lib/src/sane_html_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ class SaneHtmlValidator {
if (href != null && addLinkRel != null) {
final rels = addLinkRel!(href);
if (rels != null && rels.isNotEmpty) {
node.attributes['rel'] = rels.join(' ');
final currentRel = node.attributes['rel'] ?? '';
final allRels = <String>{
...currentRel.split(' ').where((e) => e.isNotEmpty),
...rels,
};
node.attributes['rel'] = allRels.join(' ');
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions sanitize_html/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sanitize_html
version: 2.0.0-dev
version: 2.1.0
description: >-
Function for sanitizing HTML to prevent XSS by restrict elements and
attributes to a safe subset of allowed values.
Expand All @@ -14,7 +14,7 @@ dependencies:
meta: ^1.1.7
dev_dependencies:
test: ^1.5.1
lints: ^1.0.0
markdown: ^4.0.0
lints: ^2.0.0
markdown: ^7.1.1
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.12.0 <4.0.0'

0 comments on commit 2ee4dfa

Please sign in to comment.