-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interesting bug due to Swift's set indeterminism #4
Comments
Thank you for the feedback and the research. I will try to investigate the problem and fix it as soon as I have some free time. |
Hi guys!
From my point of view it looks like you have modified the result with application of Font on Group with tested data(Text) in combination with using Because ordering of modifiers matter, it's up to programmer to choose well to avoid formatting issues... or wait to iOS 15 and use AttributedString or some other solution ¯_(ツ)_/¯ |
TL;DR: it seems that Swift's set is causing a glitch in this library in
HTML2TextParser
.Problem
Sometimes the italics effect is not applied to the following text:
<b><u><i>bolded underlined and italized</i></u></b>, normal text
.Reproduction code:
Result:
Every time the app is launched, different rows will have the glitch above.
Investigation
Initially, I thought it was a SwiftUI issue, however, this code works fine:
After digging into the library code, I noticed that in
HTML2TextParser
'saddChunkOfText(_:)
the following code is executed:AttributedText/Sources/AttributedText/HTML2TextParser.swift
Lines 101 to 105 in 26a8be0
...where
tags
is aSet<String>
.Because Swift sets are unordered, every time the
for tag in tags
code is run, a new sequence of tags is produced and different parses of the same text (like the one above) will produce a different output.In fact, if we replace the code
for tag in tags
withfor tag in tags.sorted()
, for every parse of the same text the same output will be produced. This is great, we've reached determinism. Except, now the glitch above is always present:The fix was to use another sorting order, this one works for this case:
for tag in tags.sorted(by: >)
:I'm not sure why having different tags orders cause the issue, if you have any idea, please let me know!
Thank you
The text was updated successfully, but these errors were encountered: