diff --git a/cpp/parser/GumboNormalizer.c b/cpp/parser/GumboNormalizer.c
index c41b9f5da..5a6210f15 100644
--- a/cpp/parser/GumboNormalizer.c
+++ b/cpp/parser/GumboNormalizer.c
@@ -491,7 +491,12 @@ static void emit_attributes(GumboElement *el, const char *tag_name,
if (strcmp(tag_name, "a") == 0) {
emit_one_attr(out, el, "href");
} else if (strcmp(tag_name, "img") == 0) {
- emit_one_attr(out, el, "src");
+ const char *src_val = get_attr(el, "src");
+ if (src_val && src_val[0]) {
+ emit_one_attr(out, el, "src");
+ } else {
+ buffer_append_str(out, " src=\"\"");
+ }
emit_one_attr(out, el, "alt");
emit_one_attr(out, el, "width");
emit_one_attr(out, el, "height");
diff --git a/cpp/tests/GumboParserTest.cpp b/cpp/tests/GumboParserTest.cpp
index 3101e1056..ff06232c9 100644
--- a/cpp/tests/GumboParserTest.cpp
+++ b/cpp/tests/GumboParserTest.cpp
@@ -282,6 +282,11 @@ TEST(GumboParserTest, EnrichedTagRemappings) {
EXPECT_EQ(
GumboParser::normalizeHtml("
"),
"
");
+ EXPECT_EQ(GumboParser::normalizeHtml("
"),
+ "
");
+ EXPECT_EQ(GumboParser::normalizeHtml(
+ "
"),
+ "
");
// Lists
EXPECT_EQ(GumboParser::normalizeHtml("
"),
diff --git a/ios/htmlParser/HtmlParser.mm b/ios/htmlParser/HtmlParser.mm
index 875b4d185..1b8d3fd32 100644
--- a/ios/htmlParser/HtmlParser.mm
+++ b/ios/htmlParser/HtmlParser.mm
@@ -670,7 +670,7 @@ + (NSArray *_Nonnull)getTextAndStylesFromHtml:(NSString *_Nonnull)fixedHtml
[styleArr addObject:@([ItalicStyle getType])];
} else if ([tagName isEqualToString:@"img"]) {
NSRegularExpression *srcRegex =
- [NSRegularExpression regularExpressionWithPattern:@"src=\"([^\"]+)\""
+ [NSRegularExpression regularExpressionWithPattern:@"src=\"([^\"]*)\""
options:0
error:nullptr];
NSTextCheckingResult *match =
diff --git a/src/web/__tests__/htmlNormalizer.test.ts b/src/web/__tests__/htmlNormalizer.test.ts
index d24202bbb..04547a2de 100644
--- a/src/web/__tests__/htmlNormalizer.test.ts
+++ b/src/web/__tests__/htmlNormalizer.test.ts
@@ -262,6 +262,14 @@ describe('htmlNormalizer', () => {
"
",
'
',
],
+ [
+ '
',
+ '
',
+ ],
+ [
+ '
',
+ '
',
+ ],
// Lists
['', ''],
diff --git a/src/web/normalization/htmlNormalizer.ts b/src/web/normalization/htmlNormalizer.ts
index 3f09357c1..35e6ef8a2 100644
--- a/src/web/normalization/htmlNormalizer.ts
+++ b/src/web/normalization/htmlNormalizer.ts
@@ -267,7 +267,7 @@ function emitAttributes(el: Element, name: string): string {
return emitOneAttr(el, 'href');
case 'img':
return (
- emitOneAttr(el, 'src') +
+ (el.getAttribute('src') ? emitOneAttr(el, 'src') : ' src=""') +
emitOneAttr(el, 'alt') +
emitOneAttr(el, 'width') +
emitOneAttr(el, 'height')