From 323f88dae52d63f9040d7a1a4066f8f186423af3 Mon Sep 17 00:00:00 2001 From: Siobhan <siobhan@automattic.com> Date: Tue, 27 Feb 2024 17:20:49 +0000 Subject: [PATCH 1/3] fix: Remove Video block content from post excerpt --- .../Utility/String+StripGutenbergContentForExcerpt.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift index 71c9fe6..037933c 100644 --- a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift +++ b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift @@ -19,10 +19,10 @@ extension String { return removingMatches(pattern: pattern, options: .caseInsensitive) } - /// Strips Gutenberg VideoPress block. + /// Strips VideoPress references from Gutenberg VideoPress and Video blocks. /// private func strippingGutenbergVideoPress() -> String { - let pattern = "(?s)\n?<!--\\swp:videopress/video?(.*?)wp:videopress/video\\s-->" + let pattern = "(?s)\n?<!--\\swp:video.*?(.*?)wp:video.*?\\s-->" return removingMatches(pattern: pattern, options: .caseInsensitive) } From d9d8d04cd36a0d79539e2f5c1348ae68c911fd03 Mon Sep 17 00:00:00 2001 From: Siobhan <siobhan@automattic.com> Date: Tue, 27 Feb 2024 17:26:13 +0000 Subject: [PATCH 2/3] test: Add new test to ensure video block is hidden --- .../StringStripGutenbergContentForExcerptTests.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift index e73f269..fb55293 100644 --- a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift +++ b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift @@ -38,4 +38,13 @@ class StringStripGutenbergContentForExcerptTests: XCTestCase { XCTAssertEqual(summary, expectedSummary) } + + func testStrippingGutenbergContentForExcerptWithVideoPress2() { + let content = "<p>Before</p>\n<!-- wp:video {\"guid\":\"AbCDe\",\"id\":5297} -->\n<figure class=\"wp-block-video\"><div class=\"wp-block-embed__wrapper\">\nhttps://videopress.com/v/AbCDe?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true\n</div></figure>\n<!-- /wp:video -->\n<p>After</p>" + let expectedSummary = "<p>Before</p>\n<p>After</p>" + + let summary = content.strippingGutenbergContentForExcerpt() + + XCTAssertEqual(summary, expectedSummary) + } } From 586a6be30dbf1a66de2c5a992e91274f46140c29 Mon Sep 17 00:00:00 2001 From: Siobhan <siobhan@automattic.com> Date: Tue, 27 Feb 2024 17:30:13 +0000 Subject: [PATCH 3/3] refactor: Remove trailing white space --- .../StringStripGutenbergContentForExcerptTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift index fb55293..3376ac2 100644 --- a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift +++ b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift @@ -38,7 +38,7 @@ class StringStripGutenbergContentForExcerptTests: XCTestCase { XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithVideoPress2() { let content = "<p>Before</p>\n<!-- wp:video {\"guid\":\"AbCDe\",\"id\":5297} -->\n<figure class=\"wp-block-video\"><div class=\"wp-block-embed__wrapper\">\nhttps://videopress.com/v/AbCDe?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true\n</div></figure>\n<!-- /wp:video -->\n<p>After</p>" let expectedSummary = "<p>Before</p>\n<p>After</p>"