From 9c9987535f98714c8a4ec98903f54233735ef0e4 Mon Sep 17 00:00:00 2001
From: SatowTakeshi ")
closingPTag = []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 Multiple paragraphs Multiple paragraphs Nested paragraphs
Nested
paragraphs
")}, + {[]byte("Hello
\nHello
\n