Skip to content

Render error caret for the last character of the parsing context - #627

Open
fudianchn wants to merge 1 commit into
SpongePowered:trunkfrom
fudianchn:fix-caret-last-column
Open

Render error caret for the last character of the parsing context#627
fudianchn wants to merge 1 commit into
SpongePowered:trunkfrom
fudianchn:fix-caret-last-column

Conversation

@fudianchn

Copy link
Copy Markdown

Problem

ParsingException.getMessage() renders a caret (^) under the error column, but guards it with column < context.length(). column is 1-indexed (the caret is drawn at position column - 1), so when the error is on the last character — column == context.length() — the caret is dropped (#625).

Fix

-            if (this.column >= 0 && this.column < this.context.length()) {
+            if (this.column >= 0 && this.column <= this.context.length()) {

<= renders the caret for the last character (at position column - 1), while still rejecting positions past the end.

Verification

The caret logic in isolation (the exact branch from getMessage):

column == context.length() (last char, 1-indexed):
  OLD (<):  caret rendered? false   ← bug
  NEW (<=): caret rendered? true    ← caret line "    ^" under the last char
  column=3 (mid):    OLD/NEW both render  ← no regression
  column=6 (past end): NEW no caret        ← still rejected

Added ParsingExceptionTest (caretRenderedForLastColumn / caretNotRenderedBeyondContext) — the repo's Gradle build was too heavy to run locally, but the caret logic is verified above and the test codifies it for CI.

Closes #625

ParsingException.getMessage() guards the caret rendering with
`column < context.length()`, but `column` is 1-indexed (the caret is
drawn at position `column - 1`), so when the error is at the last
character — `column == context.length()` — the caret was not rendered.

Use `<=` so the caret is shown for the last character too, while still
rejecting positions past the end of the context.

Closes SpongePowered#625

Signed-off-by: 付典 <fudianchn@gmail.com>
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.

ParsingException doesn't allow pointing to the last character

1 participant