Skip to content

Commit bff3251

Browse files
committed
Solve case where <source /> is given with no src
1 parent 5fa3818 commit bff3251

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/src/replaced_element.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ ReplacedElement parseReplacedElement(
409409
if (element.attributes['src'] != null) element.attributes['src'],
410410
...ReplacedElement.parseMediaSources(element.children),
411411
];
412-
if (sources == null || sources.isEmpty) {
412+
bool matchFound = false;
413+
for (String s in sources) {
414+
matchFound = s == null ? false : RegExp(r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$").hasMatch(s);
415+
}
416+
if (sources == null || sources.isEmpty || !matchFound) {
413417
return EmptyContentElement();
414418
}
415419
return AudioContentElement(
@@ -446,7 +450,11 @@ ReplacedElement parseReplacedElement(
446450
if (element.attributes['src'] != null) element.attributes['src'],
447451
...ReplacedElement.parseMediaSources(element.children),
448452
];
449-
if (sources == null || sources.isEmpty) {
453+
bool matchFound = false;
454+
for (String s in sources) {
455+
matchFound = s == null ? false : RegExp(r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$").hasMatch(s);
456+
}
457+
if (sources == null || sources.isEmpty || !matchFound) {
450458
return EmptyContentElement();
451459
}
452460
return VideoContentElement(

0 commit comments

Comments
 (0)