Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

NominalWordWrap merges lines separated by U+2028, U+2029, NEL or form feed into one line ("Line one" LS "Line two" → "Line one Line two") #184

Closed

Description

@matt-edmondson

What's wrong

NominalWordWrap treats only \r\n, \r and \n as forced line breaks. Unicode has other characters that also mean "end this line here":

  • U+2028 LINE SEPARATOR
  • U+2029 PARAGRAPH SEPARATOR
  • U+0085 NEXT LINE (NEL)
  • U+000C FORM FEED

Each of these is a mandatory break (class BK or NL) in UAX #14. The wrapper turns each one into an ordinary space instead. Lines the input deliberately separated get run together.

Here is the path through the code, at b019f23:

  1. StringExtensions.cs:276-277 splits segments only on \n, after NormalizeLineEndings(Unix). The AnyLineEndingRegex behind that call matches only \r\n|\r|\n.
  2. SplitAtBreakingWhiteSpace then sees char.IsWhiteSpace(ch), which is true for all four characters. It treats each one as a word separator, and the separator is rendered as a single space.

Reproduction

The source was compiled directly from main and run on net10.0. Each call uses text.NominalWordWrap(80f, 1f):

Input Output
"Line one\nLine two" ["Line one", "Line two"] (correct)
`"Line one" + '
' + "Line two"` ["Line one Line two"]
`"Para one" + '
' + "Para two"` ["Para one Para two"]
"Line one" + '\u0085' + "Line two" ["Line one Line two"]
"Page one" + '\f' + "Page two" ["Page one Page two"]
`"a" + '
' + '
' + "b"` ["a b"]: the blank line is lost too, though "a\n\nb" keeps it

Why it matters

U+2028 and U+2029 are common in real text:

  • JavaScript and JSON payloads carry them.
  • Word and rich-text editors produce them when you paste with Shift+Enter or as a paragraph mark.
  • NEL turns up in text converted from EBCDIC and other mainframe sources.

A caller that wraps such text for a console or an ImGui label gets the paragraphs merged into one run-on line. Nothing tells them anything went wrong. The function already handles NBSP, figure space, narrow NBSP, soft hyphens and surrogate pairs carefully, so this is a gap in the same Unicode handling, not a new feature.

Suggested fix

In NominalWordWrapIterator, split segments on every mandatory break, not only on \n. For example, after the existing Unix normalisation, split on '\n', ' ', ' ', '\u0085', '\f', and probably '\v' as well. Each separator then produces a line boundary, and consecutive ones produce blank lines, just as \n\n does today.

SplitAtBreakingWhiteSpace can stay as it is, because these characters will no longer reach it.

NormalizeLineEndings and DetermineLineEndings are documented in terms of CR/LF styles, so leaving them unchanged is reasonable. This issue is only about the wrapper.

Acceptance criteria

  • NominalWordWrap yields "Line one" and "Line two" as separate lines when they are separated by U+2028, U+2029, U+0085 or U+000C, at any width that fits each line.
  • Two consecutive separators yield an empty line between, matching "\n\n".
  • Data-row tests for each separator sit alongside the existing line-ending tests in Extensions.Test/StringExtensionsTests.cs.

Activity

  1. added
    bug
    on Nov 2, 2026
  2. changed the title [-]NominalWordWrap joins lines split by U+2028, U+2029 or NEL into one: "Line one⁠
Line two" at width 80 gives "Line one Line two"[/-] [+]NominalWordWrap merges lines separated by U+2028, U+2029, NEL or form feed into one line ("Line one" LS "Line two" → "Line one Line two")[/+] on Nov 2, 2026
  3. matt-edmondson commented on Nov 2, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions