Skip to content

Commit

Permalink
Merge pull request #139 from wordpress-mobile/issues/filter-gutenberg…
Browse files Browse the repository at this point in the history
…-comments

Issues/filter gutenberg comments
  • Loading branch information
aerych authored May 30, 2018
2 parents fd11b1d + e87e600 commit 22e375c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WordPressShared.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions WordPressShared/Core/Utility/RichContentFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
static let styleTags = try! NSRegularExpression(pattern: "<style[^>]*?>[\\s\\S]*?</style>", options: .caseInsensitive)
static let scriptTags = try! NSRegularExpression(pattern: "<script[^>]*?>[\\s\\S]*?</script>", options: .caseInsensitive)
static let tableTags = try! NSRegularExpression(pattern: "<table[^>]*?>[\\s\\S]*?</table>", options: .caseInsensitive)
static let gutenbergComments = try! NSRegularExpression(pattern: "<p><!-- /?wp:.+? /?--></p>[\\n]?", options: .caseInsensitive)

// Normalizaing Paragraphs
static let divTagsStart = try! NSRegularExpression(pattern: "<div[^>]*>", options: .caseInsensitive)
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions WordPressSharedTests/RichContentFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class RichContentFormatterTests: XCTestCase {


func testRemoveForbiddenTags() {
let str = "<p>test</p><p>test</p>"
let styleStr = "<script>alert();</script><style>body{color:#000;}</style><p>test</p><script>alert();</script><style>body{color:#000;}</style><p>test</p><script>alert();</script><style>body{color:#000;}</style>"
let str = "<p>test</p><p>test</p><img>"
let styleStr = "<script>alert();</script><style>body{color:#000;}</style><p>test</p><script>alert();</script><style>body{color:#000;}</style><p>test</p><p><!-- wp:paragraph {\"fontSize\":\"large\"}--></p><p><!-- /wp:paragraph --></p>\n<img><p><!-- wp:self-closing-tag /--></p><script>alert();</script><style>body{color:#000;}</style>"
let sanitizedStr = RichContentFormatter.removeForbiddenTags(styleStr)
XCTAssertTrue(str == sanitizedStr, "The forbidden tags were not removed.")
}
Expand Down

0 comments on commit 22e375c

Please sign in to comment.