Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non breaking spaces are no longer removed by WordPressEditor. #1082

Merged
merged 3 commits into from Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Aztec/Classes/Extensions/String+HTML.swift
Expand Up @@ -33,8 +33,9 @@ extension String {
///
private var entities: [Entity] {
return [
("&", "&"),
("&", "&"), // IMPORTANT: keep this first to avoid replacing the ampersand from other escaped entities.
("<", "&lt;"),
(String(.nonBreakingSpace), "&nbsp;"),
(">", "&gt;")
]
}
Expand Down
14 changes: 14 additions & 0 deletions AztecTests/TextKit/TextViewTests.swift
Expand Up @@ -1951,4 +1951,18 @@ class TextViewTests: XCTestCase {
let html = "<p><a href=\"http://wordpress.com\">WordPress</a></p>"
XCTAssertEqual(textView.getHTML(prettify: false), html)
}

// MARK: - Non-breaking spaces.

func testNonBreakingSpacesAreProperlyEncoded() {
let textView = TextViewStub(withHTML: "WordPress")

let html = "<p>&nbsp;&nbsp;</p><p>&nbsp;<br>&nbsp;</p>"
let expected = "<p>&nbsp;&nbsp;</p><p>&nbsp;<br>&nbsp;</p>"

textView.setHTML(html)
let output = textView.getHTML(prettify: false)

XCTAssertEqual(output, expected)
}
}
Expand Up @@ -209,5 +209,17 @@ class WordpressPluginTests: XCTestCase {

XCTAssertEqual(finalHTML, spacerBlock)
}

// MARK: - Non-breaking spaces.

func testNonBreakingSpacesAreProperlyEncoded() {
let html = "<p>&nbsp;&nbsp;</p><p>&nbsp;<br>&nbsp;</p>"
let expected = "&nbsp;&nbsp;\n\n&nbsp;\n&nbsp;"

let attributedString = htmlConverter.attributedString(from: html)
let finalHTML = htmlConverter.html(from: attributedString)

XCTAssertEqual(finalHTML, expected)
}
}