SwiftSoup icon indicating copy to clipboard operation
SwiftSoup copied to clipboard

Crash CharacterReader.matchesAny(_:)

Open DevOpsAppsIOL opened this issue 4 weeks ago • 5 comments

Hello, My app is crashing so many times. From Firebase Crashlytics I have this data:

      Crashed: com.apple.main-thread
      0  My App                    0xe68318 CharacterReader.matchesAny(_:) + 20 (ParsingStrings.swift:20)
      1  My App                    0xf0ae80 Tokeniser.consumeCharacterReference(_:_:) + 189 (Tokeniser.swift:189)
      2  My App                    0xf0efe4 TokeniserState.read(_:_:) + 857 (TokeniserState.swift:857)
      3  My App                    0xeead64 specialized static Parser.parse(_:_:) + 47 (Tokeniser.swift:47)
      4  My App                    0xefcda8 parse(_:) + 70 (SwiftSoup.swift:70)

my code is: let text: String = ...... let doc: Document = try SwiftSoup.parse(text) let plainText = try doc.body()?.text()

I don't know the content of text and therefore I'm not able to replicate the problem. I am currently using version 2.11.1

DevOpsAppsIOL avatar Dec 01 '25 13:12 DevOpsAppsIOL

I managed to replicate the crash with this String:

let text = "<a href='&lt"

As you can see it crashes

Task 3: Fatal error: Index out of range

Image

SwiftSoup version 2.11.2

DevOpsAppsIOL avatar Dec 01 '25 14:12 DevOpsAppsIOL

Thanks for the detailed report

If you can submit a fix PR, I can review and merge it. We are all volunteers here and I don't have time to investigate and fix this at the moment (and I work for myself so I don't have an employer to petition for company time to look into this either) but can assist you with contributing a resolution. Even if you have just a test case that reproduces the issue, that is helpful in reducing the work required to merge a fix.

aehlke avatar Dec 01 '25 16:12 aehlke

Hello @aehlke,

I prepared the fix but I don't have permissions to push the code to a branch. Can you give me access or tell me how to open a PR? Thank you

DevOpsAppsIOL avatar Dec 02 '25 08:12 DevOpsAppsIOL

Great thank you - https://github.com/scinfu/SwiftSoup/pulls and select 'New pull request' (green button), then select your fork

aehlke avatar Dec 02 '25 18:12 aehlke

Hello @aehlke, I created the PR https://github.com/scinfu/SwiftSoup/pull/357.

Thanks for the support.

DevOpsAppsIOL avatar Dec 03 '25 07:12 DevOpsAppsIOL

Hello, My app is crashing so many times. From Firebase Crashlytics I have this data:

      Crashed: com.apple.main-thread
      0  My App                    0xe68318 CharacterReader.matchesAny(_:) + 20 (ParsingStrings.swift:20)
      1  My App                    0xf0ae80 Tokeniser.consumeCharacterReference(_:_:) + 189 (Tokeniser.swift:189)
      2  My App                    0xf0efe4 TokeniserState.read(_:_:) + 857 (TokeniserState.swift:857)
      3  My App                    0xeead64 specialized static Parser.parse(_:_:) + 47 (Tokeniser.swift:47)
      4  My App                    0xefcda8 parse(_:) + 70 (SwiftSoup.swift:70)

my code is: let text: String = ...... let doc: Document = try SwiftSoup.parse(text) let plainText = try doc.body()?.text()

I don't know the content of text and therefore I'm not able to replicate the problem. I am currently using version 2.11.1

Rezajamalirj avatar Dec 07 '25 11:12 Rezajamalirj

@DevOpsAppsIOL please update it should be fixed now

aehlke avatar Dec 07 '25 14:12 aehlke