strings.truncate can freeze when in a fast event/strings.strcharpart's fallback is used

Open Beginner friendly
#682 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
lua
Domain
tooling

Research direction

Open lua/plenary/strings.lua and inspect the strings.strcharpart fallback around the referenced lines, then trace how truncate calls it for positive direction. Verify that the fallback’s substring behavior matches the stated start-and-length expectation and that truncate("test string", 5, "...", 1) completes instead of freezing.

Written by the indexing model from the issue text.

Description

(I saw the no longer maintained sign, consider this for documentation purposes or something)

there's an oopsie in strings.strcharpart's fallback function. sub takes start and end positions, and not start and length like vim's strcharpart:
https://github.com/nvim-lua/plenary.nvim/blob/74b06c6c75e4eeb3108ec01852001636d85a932b/lua/plenary/strings.lua#L42-L45

when this fallback function is used, the truncate function can get stuck in an infinite loop whenever the direction is positive and the string is long enough to be truncated. for example, this freezes in a fast state:

truncate("test string", 5, "...", 1)

to fix this, I think the fallback just needs to be: return str:sub(nchar + 1, nchar + charlen)

Dominant language
Lua
Stars
3.5k
Forks
340
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from nvim-lua/plenary.nvim

All issues in nvim-lua/plenary.nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.