From 290dc1fb11f8cc37d34a6a4f746c40f8e35e5000 Mon Sep 17 00:00:00 2001 From: aerych Date: Tue, 29 May 2018 15:27:53 -0500 Subject: [PATCH 1/5] Treat Gutenberg comments as forbidden tags. --- WordPressShared/Core/Utility/RichContentFormatter.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPressShared/Core/Utility/RichContentFormatter.swift b/WordPressShared/Core/Utility/RichContentFormatter.swift index 8e9feac..820c86a 100644 --- a/WordPressShared/Core/Utility/RichContentFormatter.swift +++ b/WordPressShared/Core/Utility/RichContentFormatter.swift @@ -11,6 +11,7 @@ import Foundation static let styleTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let scriptTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let tableTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) + static let gutenbergComments = try! NSRegularExpression(pattern: "

", options: .caseInsensitive) // Normalizaing Paragraphs static let divTagsStart = try! NSRegularExpression(pattern: "]*>", options: .caseInsensitive) @@ -84,6 +85,11 @@ import Foundation range: NSRange(location: 0, length: content.count), withTemplate: "") + content = RegEx.gutenbergComments.stringByReplacingMatches(in: content, + options: .reportCompletion, + range: NSRange(location: 0, length: content.count), + withTemplate: "") + return content } From aa7a34d4b6cfaa4804761dddedf6ffa4259eb6ee Mon Sep 17 00:00:00 2001 From: aerych Date: Tue, 29 May 2018 17:18:57 -0500 Subject: [PATCH 2/5] Tweak regex to catch gutenberg attributes. --- WordPressShared/Core/Utility/RichContentFormatter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressShared/Core/Utility/RichContentFormatter.swift b/WordPressShared/Core/Utility/RichContentFormatter.swift index 820c86a..58d6a85 100644 --- a/WordPressShared/Core/Utility/RichContentFormatter.swift +++ b/WordPressShared/Core/Utility/RichContentFormatter.swift @@ -11,7 +11,7 @@ import Foundation static let styleTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let scriptTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let tableTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) - static let gutenbergComments = try! NSRegularExpression(pattern: "

", options: .caseInsensitive) + static let gutenbergComments = try! NSRegularExpression(pattern: "

[\\n]?", options: .caseInsensitive) // Normalizaing Paragraphs static let divTagsStart = try! NSRegularExpression(pattern: "]*>", options: .caseInsensitive) From afee0e92d755f1a4fe9c4761414a70bf9a509cc8 Mon Sep 17 00:00:00 2001 From: aerych Date: Tue, 29 May 2018 17:19:13 -0500 Subject: [PATCH 3/5] Update test. --- WordPressSharedTests/RichContentFormatterTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPressSharedTests/RichContentFormatterTests.swift b/WordPressSharedTests/RichContentFormatterTests.swift index c6197d6..c96ff3d 100644 --- a/WordPressSharedTests/RichContentFormatterTests.swift +++ b/WordPressSharedTests/RichContentFormatterTests.swift @@ -12,8 +12,8 @@ class RichContentFormatterTests: XCTestCase { func testRemoveForbiddenTags() { - let str = "

test

test

" - let styleStr = "

test

test

" + let str = "

test

test

" + let styleStr = "

test

test

\n" let sanitizedStr = RichContentFormatter.removeForbiddenTags(styleStr) XCTAssertTrue(str == sanitizedStr, "The forbidden tags were not removed.") } From 0c1d2341bcf38b73beb4100b1ee5847e831dcd6b Mon Sep 17 00:00:00 2001 From: aerych Date: Tue, 29 May 2018 20:57:06 -0500 Subject: [PATCH 4/5] Handle self-closing gutenberg tags. --- WordPressShared/Core/Utility/RichContentFormatter.swift | 2 +- WordPressSharedTests/RichContentFormatterTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPressShared/Core/Utility/RichContentFormatter.swift b/WordPressShared/Core/Utility/RichContentFormatter.swift index 58d6a85..4736ccb 100644 --- a/WordPressShared/Core/Utility/RichContentFormatter.swift +++ b/WordPressShared/Core/Utility/RichContentFormatter.swift @@ -11,7 +11,7 @@ import Foundation static let styleTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let scriptTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) static let tableTags = try! NSRegularExpression(pattern: "]*?>[\\s\\S]*?", options: .caseInsensitive) - static let gutenbergComments = try! NSRegularExpression(pattern: "

[\\n]?", options: .caseInsensitive) + static let gutenbergComments = try! NSRegularExpression(pattern: "

[\\n]?", options: .caseInsensitive) // Normalizaing Paragraphs static let divTagsStart = try! NSRegularExpression(pattern: "]*>", options: .caseInsensitive) diff --git a/WordPressSharedTests/RichContentFormatterTests.swift b/WordPressSharedTests/RichContentFormatterTests.swift index c96ff3d..76273a4 100644 --- a/WordPressSharedTests/RichContentFormatterTests.swift +++ b/WordPressSharedTests/RichContentFormatterTests.swift @@ -13,7 +13,7 @@ class RichContentFormatterTests: XCTestCase { func testRemoveForbiddenTags() { let str = "

test

test

" - let styleStr = "

test

test

\n" + let styleStr = "

test

test

\n

" let sanitizedStr = RichContentFormatter.removeForbiddenTags(styleStr) XCTAssertTrue(str == sanitizedStr, "The forbidden tags were not removed.") } From e87e600a8247bb7f17928135b93a550f899e7fed Mon Sep 17 00:00:00 2001 From: aerych Date: Tue, 29 May 2018 20:57:14 -0500 Subject: [PATCH 5/5] Bumps pod version. --- WordPressShared.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressShared.podspec b/WordPressShared.podspec index 93ea90a..26144a5 100644 --- a/WordPressShared.podspec +++ b/WordPressShared.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressShared" - s.version = "1.0.4" + s.version = "1.0.5" s.summary = "Shared components used in building the WordPress iOS apps and other library components." s.description = <<-DESC