Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,20 @@ private static <T> void startImg(
int len = text.length();
text.append("");
Object imageSpan =
spanFactory.createImageSpan(src, Integer.parseInt(width), Integer.parseInt(height));
spanFactory.createImageSpan(src, parseDimension(width), parseDimension(height));
text.setSpan(imageSpan, len, text.length(), EnrichedSpanFlags.forSpan(imageSpan));
}

private static int parseDimension(String value) {
if (value == null) return 0;
try {
int parsed = (int) Math.floor(Float.parseFloat(value));
return Math.max(parsed, 0);
} catch (NumberFormatException e) {
return 0;
}
}

private static void startA(Editable text, Attributes attributes) {
String href = attributes.getValue("", "href");
start(text, new Href(href));
Expand Down
5 changes: 3 additions & 2 deletions ios/htmlParser/HtmlParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,9 @@ + (NSString *)tagContentForStyle:(NSNumber *)style
ImageData *data = [imageStyle getImageDataAt:location];
if (data != nullptr && data.uri != nullptr) {
return [NSString
stringWithFormat:@"img src=\"%@\" width=\"%f\" height=\"%f\"",
data.uri, data.width, data.height];
stringWithFormat:@"img src=\"%@\" width=\"%d\" height=\"%d\"",
data.uri, (int)floor(data.width),
(int)floor(data.height)];
}
}
return @"img";
Expand Down
Loading