diff --git a/Aztec/Classes/Extensions/String+HTML.swift b/Aztec/Classes/Extensions/String+HTML.swift index d53f51f98..38718eca8 100644 --- a/Aztec/Classes/Extensions/String+HTML.swift +++ b/Aztec/Classes/Extensions/String+HTML.swift @@ -33,8 +33,9 @@ extension String { /// private var entities: [Entity] { return [ - ("&", "&"), + ("&", "&"), // IMPORTANT: keep this first to avoid replacing the ampersand from other escaped entities. ("<", "<"), + (String(.nonBreakingSpace), " "), (">", ">") ] } diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index 9c0e08990..9e2274cb9 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -1951,4 +1951,18 @@ class TextViewTests: XCTestCase { let html = "
" XCTAssertEqual(textView.getHTML(prettify: false), html) } + + // MARK: - Non-breaking spaces. + + func testNonBreakingSpacesAreProperlyEncoded() { + let textView = TextViewStub(withHTML: "WordPress") + + let html = "