From a65920aa70cd68c33ae05761ca9178b37bd372db Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 7 Oct 2025 19:07:33 +0200 Subject: [PATCH] Check type assertions for content types --- content.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/content.go b/content.go index 3eafde5..048e57a 100644 --- a/content.go +++ b/content.go @@ -21,13 +21,22 @@ type Content interface { func NewContent(contentType int, mediaType string, content any) Content { switch contentType { case 0: - return newInlineTextContent(mediaType, content.(string)) + if stringContent, ok := content.(string); ok { + return newInlineTextContent(mediaType, stringContent) + } + return nil case 1: - return newInlineXHTMLContent(mediaType, content.(*XHTMLDiv)) + if xhtmlDivContent, ok := content.(*XHTMLDiv); ok { + return newInlineXHTMLContent(mediaType, xhtmlDivContent) + } + return nil case 2: return newInlineOtherContent(mediaType, content) case 3: - return newOutOfLineContent(mediaType, content.(string)) + if stringContent, ok := content.(string); ok { + return newOutOfLineContent(mediaType, stringContent) + } + return nil default: return nil }