From 0b2d595c64dfd5770264fda314cde8ee2f45bf96 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Mon, 11 May 2020 22:26:20 +0100 Subject: [PATCH 1/4] Fix collapse of white spaces when parsing HTML text. --- Aztec/Classes/Libxml2/Converters/In/HTMLParser.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Aztec/Classes/Libxml2/Converters/In/HTMLParser.swift b/Aztec/Classes/Libxml2/Converters/In/HTMLParser.swift index 4b49016b5..2866a92ba 100644 --- a/Aztec/Classes/Libxml2/Converters/In/HTMLParser.swift +++ b/Aztec/Classes/Libxml2/Converters/In/HTMLParser.swift @@ -45,12 +45,16 @@ open class HTMLParser { // htmlHandleOmittedElem(0) + var parserOptions = HTML_PARSE_RECOVER.rawValue | HTML_PARSE_NODEFDTD.rawValue | HTML_PARSE_NOERROR.rawValue | HTML_PARSE_NOWARNING.rawValue | HTML_PARSE_NOIMPLIED.rawValue + if shouldCollapseSpaces { + parserOptions = parserOptions | HTML_PARSE_NOBLANKS.rawValue + } let document = htmlCtxtReadMemory(parserContext, htmlPtr, Int32(wrappedHTML.lengthOfBytes(using: String.Encoding.utf8)), "", "UTF-8", - Int32(HTML_PARSE_RECOVER.rawValue | HTML_PARSE_NODEFDTD.rawValue | HTML_PARSE_NOERROR.rawValue | HTML_PARSE_NOWARNING.rawValue | HTML_PARSE_NOIMPLIED.rawValue | HTML_PARSE_NOBLANKS.rawValue)) + Int32(parserOptions)) defer { xmlFreeDoc(document) From 7d468c91a66ff07f937652cb279fca1037b3ffb3 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Mon, 11 May 2020 23:03:00 +0100 Subject: [PATCH 2/4] Improve unit test. --- AztecTests/TextKit/TextStorageTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AztecTests/TextKit/TextStorageTests.swift b/AztecTests/TextKit/TextStorageTests.swift index acae93ae2..d66fa0f69 100644 --- a/AztecTests/TextKit/TextStorageTests.swift +++ b/AztecTests/TextKit/TextStorageTests.swift @@ -566,7 +566,7 @@ class TextStorageTests: XCTestCase { /// Verifies that spaces are not collapsed /// func testConverterCollapsesSpacesText() { - let initialHTML = "

Hello World

" + let initialHTML = "

Hello
World

" // Setup let defaultAttributes: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 14), @@ -575,7 +575,7 @@ class TextStorageTests: XCTestCase { storage.htmlConverter.shouldCollapseSpaces = false storage.setHTML(initialHTML, defaultAttributes: defaultAttributes) - let expectedResult = "

Hello World

" + let expectedResult = "

Hello
World

" let result = storage.getHTML() XCTAssertEqual(expectedResult, result) } From 8fd4180200d5c017146ec60b5aecedd6ea912481 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 12 May 2020 15:33:12 +0100 Subject: [PATCH 3/4] Update tests. --- AztecTests/TextKit/TextStorageTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AztecTests/TextKit/TextStorageTests.swift b/AztecTests/TextKit/TextStorageTests.swift index d66fa0f69..c80a35a36 100644 --- a/AztecTests/TextKit/TextStorageTests.swift +++ b/AztecTests/TextKit/TextStorageTests.swift @@ -566,7 +566,7 @@ class TextStorageTests: XCTestCase { /// Verifies that spaces are not collapsed /// func testConverterCollapsesSpacesText() { - let initialHTML = "

Hello
World

" + let initialHTML = "

Hello
World

" // Setup let defaultAttributes: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 14), @@ -575,7 +575,7 @@ class TextStorageTests: XCTestCase { storage.htmlConverter.shouldCollapseSpaces = false storage.setHTML(initialHTML, defaultAttributes: defaultAttributes) - let expectedResult = "

Hello
World

" + let expectedResult = "

Hello
World

" let result = storage.getHTML() XCTAssertEqual(expectedResult, result) } From bb5316b7624d193b1fa8c621838f2599b8ba5f2a Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 12 May 2020 18:06:11 +0100 Subject: [PATCH 4/4] Bump version to 1.19.1 --- CHANGELOG.md | 4 ++++ WordPress-Aztec-iOS.podspec | 2 +- WordPress-Editor-iOS.podspec | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c53039c..635240b3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +1.19.1 +------- +* Fix a bug where collapse of whitespaces was happening for empty HTML nodes. + 1.19.0 ------- * Add support for the sup and sub HTML tags. diff --git a/WordPress-Aztec-iOS.podspec b/WordPress-Aztec-iOS.podspec index 5d704b54b..ffafac692 100644 --- a/WordPress-Aztec-iOS.podspec +++ b/WordPress-Aztec-iOS.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'WordPress-Aztec-iOS' - s.version = '1.19.0' + s.version = '1.19.1' s.summary = 'The native HTML Editor.' # This description is used to generate tags and improve search results. diff --git a/WordPress-Editor-iOS.podspec b/WordPress-Editor-iOS.podspec index e1ab31541..cdbf801bc 100644 --- a/WordPress-Editor-iOS.podspec +++ b/WordPress-Editor-iOS.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'WordPress-Editor-iOS' - s.version = '1.19.0' + s.version = '1.19.1' s.summary = 'The WordPress HTML Editor.' # This description is used to generate tags and improve search results.