jpsim / jpsim/SourceKitten

Crash on unicode characters used after string interpolation

Open
#444 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
2.4k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

sourcekitten structure returns wrong key.length when unicode characters are used after string interpolation. Here is an example:

sourcekitten structure --text 'class Foo { var blah: String { switch { default: return "\(true) π" }}}'

It will always give 26 for length of case statement:

"key.kind" : "source.lang.swift.stmt.case",
"key.offset" : 40,
"key.length" : 26

At the same time when unicode character comes before string interpolation length is completely different.

sourcekitten structure --text 'class Foo { var blah: String { switch { default: return "π \(true)" }}}'

"key.kind" : "source.lang.swift.stmt.case",
"key.offset" : 40,
"key.length" : 32

but again adding whitespaces after string interpolation does not change the length, which will probably lead to crash again.

Crash happens when trying to extract string for such statement from the source:

frame #7: 0x000000010e443ac0 SourceKittenFramework`NSString.CacheContainer.location(byteOffset=91, self=0x00007fabf73072d0) at String+SourceKitten.swift:129

Reference
https://github.com/krzysztofzablocki/Sourcery/issues/432

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sourcekitten structure --text reproductions and inspect String+SourceKitten.swift around NSString.CacheContainer.location at line 129. Compare the reported offsets and lengths for unicode before and after interpolation, then verify that extracting the case statement no longer crashes and that the reported length is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.