Skip to content

Conversation

@lethalbit
Copy link

@lethalbit lethalbit commented Apr 27, 2025

Within Writer::write_str there is a bug in the line wrapping logic, where if the offset is ever 0, it would never force a hard-wrap and cause the poor line wrapping code to spin forever, hopelessly trying its best, but making no progress.

There are 2 cases where offset can be 0, the first is when it can't find any whitespace to wrap on, and the second being when the very last character of the wrap boundary was whitespace.

This fixes the primary problem by always forcing an ugly hard-wrap at the boundary if offset is ever 0, and updating the offset value to be that boundary limit. This then allows the sub-slice of the line to work as expected and not run in circles forever.

EDIT: Turns out there are still a few edge cases, i'll keep poking it :v

There was a fun bug where if the offset in the line-wrapping was ever 0, it would never force a hard-wrap at the limit and also set the line back to itself in the slice.

As such it would just hopelessly spin forever trying its best to wrap a line.

This bug would also happen if the character that landed *right* on the end of the wrapping boundary was whitespace, causing the offset to be 0.
@lethalbit lethalbit marked this pull request as draft April 27, 2025 09:40
@hawkw
Copy link
Owner

hawkw commented Apr 27, 2025

Thank you for looking at this! We could probably also write some tests for this stuff (running on the development system with std) to catch some of those edge cases, but...I've been too lazy to actually do that. It's totally fine if you are too... :)

@lethalbit
Copy link
Author

Yeah no problem! I was ahem borrowing a big chunk of the code for a thing I'm working on when I found the bug :v

Some proper tests would be nice, but alas, the spoons and effort needed is not in the budget right now, for me at least.

As for the edge cases I found, there are some very rare cases where line wrapping just goes mental, I suspect there is a subtle off-by-one somewhere, where it imagines that it can to a soft-wrap right after the first character?

This also seemes very inconsistent, as most of the time it would be fine, but then sometimes just, has a conniption

image image

I've just given up for what i'm doing and force a hard-wrap at the boundary every time, but fixing it would be nice, lol

@iximeow
Copy link
Collaborator

iximeow commented Dec 27, 2025

oh! i ended up making a similar change in #551, but:

the second being when the very last character of the wrap boundary was whitespace.

totally missed that. that bug's still there.

@lethalbit
Copy link
Author

I think I fixed this on my end months ago and just forgor to update this PR,

I can do so and update this PR or just drop this one and it can be done elsewhere, i'm good with whatever, just let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants