MacDownApp / MacDownApp/macdown

Should promise UTF-16 surrogate pairs handling

Open
#112 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rich Text Format
Stars
9.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Time to face this. After manual inspection all -characterAtIndex: calls seem to be fine, but there are at least a couple of places where string length are assumed to be equal to character count. Some examples:

  1. Length of a single-character string are assumed to be 1. For example, NSMakeRange(location, 1) is used to acquire the substring range of it in a string. Should use str.length instead.
  2. -length is used as character count in the string. This is a problem for the word counter, for which trimmedDocument.length is used to count characters. Should use substring enumeration with NSStringEnumerationByComposedCharacterSequences to count that manually instead.

There are likely more. Things in NSDocument can be inspected manually (not that much text processing logic there), but unit tests are needed in other classes.


Edit: NSLayoutManager’s glyph API might also be useful. I suspect that would be slower, though, since they usually generate NSGlyph instances. Maybe some benchmarking is needed?

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

Inspect the text-processing logic in NSDocument and the other classes containing NSMakeRange(..., 1) or -length character-count assumptions. Add unit tests for surrogate pairs and composed character sequences, and use the tests to identify remaining incorrect counts; done means the affected cases handle UTF-16 strings correctly and the test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.