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 = "

WordPress

" XCTAssertEqual(textView.getHTML(prettify: false), html) } + + // MARK: - Non-breaking spaces. + + func testNonBreakingSpacesAreProperlyEncoded() { + let textView = TextViewStub(withHTML: "WordPress") + + let html = "

  

 
 

" + let expected = "

  

 
 

" + + textView.setHTML(html) + let output = textView.getHTML(prettify: false) + + XCTAssertEqual(output, expected) + } } diff --git a/WordPressEditor/WordPressEditorTests/WordPressPlugin/WordPressPluginTests.swift b/WordPressEditor/WordPressEditorTests/WordPressPlugin/WordPressPluginTests.swift index da0bd6254..b5c733251 100644 --- a/WordPressEditor/WordPressEditorTests/WordPressPlugin/WordPressPluginTests.swift +++ b/WordPressEditor/WordPressEditorTests/WordPressPlugin/WordPressPluginTests.swift @@ -209,5 +209,17 @@ class WordpressPluginTests: XCTestCase { XCTAssertEqual(finalHTML, spacerBlock) } + + // MARK: - Non-breaking spaces. + + func testNonBreakingSpacesAreProperlyEncoded() { + let html = "

  

 
 

" + let expected = "  \n\n \n " + + let attributedString = htmlConverter.attributedString(from: html) + let finalHTML = htmlConverter.html(from: attributedString) + + XCTAssertEqual(finalHTML, expected) + } }