From 0804f3359d8246437e010087693408df723f9deb Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 4 Apr 2022 20:02:47 -0400 Subject: [PATCH] Fix indexes when working with characters containing multiple unicode scalars --- Source/Formatting.swift | 3 +++ Tests/FormattingTests.swift | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Formatting.swift b/Source/Formatting.swift index 5708a02..e9534a7 100644 --- a/Source/Formatting.swift +++ b/Source/Formatting.swift @@ -118,6 +118,9 @@ private final class Parser: NSObject, XMLParserDelegate { let output = NSMutableAttributedString(string: text) // Apply tags in reverse, more specific tags are applied last. for (range, attributes) in attributes.reversed() { + let lb = text.index(text.startIndex, offsetBy: range.lowerBound) + let ub = text.index(text.startIndex, offsetBy: range.upperBound) + let range = NSRange(lb..