From 57ec491bace43bdca4b6e0e2558a14cf2621a455 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 22 Sep 2025 09:27:14 +0300 Subject: [PATCH] Fixes #4529 - Order out of order ordered list ordering order --- .../HTMLParsing/AttributedStringBuilderV2.swift | 4 ++++ .../Sources/AttributedStringBuilderTests.swift | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift index 2565f98ae..a757d7b35 100644 --- a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift +++ b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift @@ -206,6 +206,10 @@ struct AttributedStringBuilderV2: AttributedStringBuilderProtocol { case "ul", "ol": var listIndex = 1 + if let startAttribute = try? childElement.attr("start"), let startIndex = Int(startAttribute) { + listIndex = startIndex + } + content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: tag, listIndex: &listIndex, indentLevel: indentLevel + 1) case "li": diff --git a/UnitTests/Sources/AttributedStringBuilderTests.swift b/UnitTests/Sources/AttributedStringBuilderTests.swift index f8a977c27..93a50320e 100644 --- a/UnitTests/Sources/AttributedStringBuilderTests.swift +++ b/UnitTests/Sources/AttributedStringBuilderTests.swift @@ -753,6 +753,21 @@ class AttributedStringBuilderV1Tests: XCTestCase { } } + func testOutOfOrderListNubmering() { + let htmlString = "
    \n
  1. this is a two
  2. \n
" + + guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { + XCTFail("Could not build the attributed string") + return + } + + if AttributedStringBuilder.useNextGenHTMLParser { + XCTAssertEqual(String(attributedString.characters), " 2. this is a two") + } else { + XCTAssertEqual(String(attributedString.characters), "\t2.\tthis is a two") + } + } + // MARK: - Phishing prevention func testPhishingLink() {