fixup! TF-4224 Reduce ReDoS vulnerability
This commit is contained in:
@@ -9,6 +9,8 @@ abstract class DomTransformer {
|
||||
|
||||
const DomTransformer();
|
||||
|
||||
static final _backgroundImageRegex = RegExp(r'''\bbackground-image\s*:\s*url\(\s*['"]?([^' ")]+)['"]?\s*\)''');
|
||||
|
||||
/// Uses the `DOM` [document] to transform the `document`.
|
||||
///
|
||||
/// All changes will be visible to subsequent transformers.
|
||||
@@ -27,8 +29,7 @@ abstract class DomTransformer {
|
||||
|
||||
Tuple2<String, String>? findImageUrlFromStyleTag(String style) {
|
||||
try {
|
||||
final regExp = RegExp(r'''\bbackground-image\s*:\s*url\(\s*['"]?([^' ")]+)['"]?\s*\)''');
|
||||
final match = regExp.firstMatch(style);
|
||||
final match = _backgroundImageRegex.firstMatch(style);
|
||||
if (match == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ class NormalizeLineHeightInStyleTransformer extends DomTransformer {
|
||||
const NormalizeLineHeightInStyleTransformer();
|
||||
|
||||
static const _removableLineHeights = ['1px', '100%'];
|
||||
static final _multipleSpacesRegex = RegExp(r' {2,}');
|
||||
|
||||
@override
|
||||
Future<void> process({
|
||||
@@ -30,7 +31,7 @@ class NormalizeLineHeightInStyleTransformer extends DomTransformer {
|
||||
var updatedStyle = originalStyle.replaceAll(pattern, '').trim();
|
||||
|
||||
// Remove extra spaces (>=2 spaces → 1 space)
|
||||
updatedStyle = updatedStyle.replaceAll(RegExp(r' {2,}'), ' ');
|
||||
updatedStyle = updatedStyle.replaceAll(_multipleSpacesRegex, ' ');
|
||||
|
||||
if (updatedStyle != originalStyle) {
|
||||
if (updatedStyle.isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user