From 1f7f7966ef6fd87218df0bfae1bd0eae419bd7aa Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 15 Oct 2024 21:47:13 +0200 Subject: [PATCH] Add check for whether a mime type is used for inline other and out of line content --- inlineOtherContent.go | 8 +++++++- outOfLineContent.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/inlineOtherContent.go b/inlineOtherContent.go index 7c7c650..c381e08 100644 --- a/inlineOtherContent.go +++ b/inlineOtherContent.go @@ -27,7 +27,13 @@ func (i *InlineOtherContent) hasSRC() bool { return false } func (i *InlineOtherContent) getType() string { return string(i.Type) } func (i *InlineOtherContent) Check() error { - if isCompositeMediaType(i.getType()) { + mediaType := i.getType() + + if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil { + return fmt.Errorf("type attribute %v incompatible with inline other content", mediaType) + } + + if isCompositeMediaType(mediaType) { return errors.New("type attribute of inline other content must not be a composite type") } diff --git a/outOfLineContent.go b/outOfLineContent.go index dfc3871..bd11531 100644 --- a/outOfLineContent.go +++ b/outOfLineContent.go @@ -37,7 +37,13 @@ func (o *OutOfLineContent) hasSRC() bool { return true } func (o *OutOfLineContent) getType() string { return string(o.Type) } func (o *OutOfLineContent) Check() error { - if isCompositeMediaType(o.getType()) { + mediaType := o.getType() + + if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil { + return fmt.Errorf("type attribute %v incompatible with out of line content", mediaType) + } + + if isCompositeMediaType(mediaType) { return errors.New("type attribute of out of line content must not be a composite type") }