diff --git a/helpers/content.go b/helpers/content.go index e61888357..5eeca88b6 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -44,6 +44,7 @@ var ( openingPTag = []byte("

") closingPTag = []byte("

") paragraphIndicator = []byte(" tags in the input and enclose the content // of the input (whitespace excluded). func (c *ContentSpec) TrimShortHTML(input []byte) []byte { - first := bytes.Index(input, paragraphIndicator) - last := bytes.LastIndex(input, paragraphIndicator) - if first == last { + firstOpeningP := bytes.Index(input, paragraphIndicator) + lastOpeningP := bytes.LastIndex(input, paragraphIndicator) + + lastClosingP := bytes.LastIndex(input, closingPTag) + lastClosing := bytes.LastIndex(input, closingIndicator) + + if firstOpeningP == lastOpeningP && lastClosingP == lastClosing { input = bytes.TrimSpace(input) input = bytes.TrimPrefix(input, openingPTag) input = bytes.TrimSuffix(input, closingPTag) diff --git a/helpers/content_test.go b/helpers/content_test.go index 7f82abc9d..86e5412c2 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -41,6 +41,7 @@ func TestTrimShortHTML(t *testing.T) { {[]byte("\n \n \t

\t Whitespace\nHTML \n\t

\n\t"), []byte("Whitespace\nHTML")}, {[]byte("

Multiple

paragraphs

"), []byte("

Multiple

paragraphs

")}, {[]byte("

Nested

paragraphs

"), []byte("

Nested

paragraphs

")}, + {[]byte("

Hello

\n"), []byte("

Hello

\n")}, } c := newTestContentSpec()