Fix getSelectedText overflow, align sort semantics with IDEA core, v11.0.3 - #12
Merged
Conversation
SCI_GETSELTEXT in Scintilla >= 5.1.5 (Notepad++ bundles >= 5.2.3, per the Scintilla.h deprecation note) returns the selection length EXCLUDING the terminating NUL, and the fill call still writes that NUL. getSelectedText allocated exactly `length` bytes, so the fill wrote length+1 bytes, one past the end of the heap buffer. Allocate `length + 1`, matching the +1 already used by getRangeText, nativeLangFileName, and pluginConfigFilePath. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEUknRbMeu7qwvi8QGZ48z
Scintilla >= 5.1.5 returns the selection length excluding the NUL from SCI_GETSELTEXT(0,0), so an empty selection reports 0 and a one-character selection reports 1. The old guard 'lengthResult <= 1' was written for the pre-5.1.5 semantics (length including NUL) and now silently drops one-character selections in getSelectedText. Lower the guard to 'lengthResult <= 0'. Under the legacy semantics an empty selection reports 1, and the length + 1 buffer stays NUL-filled, so the function still returns an empty string there; real selections are unaffected either way. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Joint fix with IdeaMarkdownTableEditor so both plugin cores keep
producing identical output (shared golden fixtures stay byte-equal).
- Make the sort comparator a total order: rows with strict-decimal
values group before textual rows instead of comparing numerically
against some rows and textually against others. The old mixed
comparison was intransitive ('10' < '1z' < '9' < '10'), which is
not a strict weak ordering, so std::stable_sort invoked undefined
behavior on such columns.
- Restrict numeric sort keys to a strict decimal grammar shared with
the Java core. strtod also accepts 'inf', 'nan', and hex floats
like '0x10', which Double.parseDouble either rejects or spells
differently, so the same column sorted differently in the two
plugins. NaN keys are no longer possible.
- Pin the numeric parse to the C locale via _strtod_l. A host process
running under a comma-decimal locale would otherwise parse '1.5'
as 1 and diverge from the IntelliJ plugin.
- Add golden fixtures locking the number-vs-text grouping and the
+0/-0 tie-break; the same fixtures land in IdeaMarkdownTableEditor.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Extend the strict-decimal sort fixture with exponent forms (2e3, 5e-1, 1e+2, 3E2), rejected shapes (7e, lone '-'), a soft-hyphen cell, and a plane-15 code point so the shared grammar's exponent branches, the format-code-point path, and the code-point-table exhaustion path are all exercised by the golden contract in both plugin cores. Mirrored byte-for-byte in IdeaMarkdownTableEditor. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Joint bug-fix release with krotname/IdeaMarkdownTableEditor keeping the shared core in lockstep. The golden fixture file stays byte-identical between both repos.
Fixes
getSelectedText: Scintilla >= 5.1.5 returns the selection length excluding the terminating NUL fromSCI_GETSELTEXT(0,0), but the fill still writes the NUL. The buffer was sizedlength, so the fill wrotelength + 1bytes. Now allocateslength + 1(from the repository-audit branch).lengthResult <= 1guard encoded the pre-5.1.5 semantics (length including NUL) and silently treated 1-byte selections as empty. Lowered to<= 0; still returns an empty string under legacy semantics.'10' < '1z' < '9' < '10'— not a strict weak ordering, sostd::stable_sortinvoked undefined behavior. Strict-decimal rows now group before textual rows — a proper total order, same as the Java core.strtodacceptedinf,nan, hex0x10whileDouble.parseDoubleaccepted1.5f,Infinity— the same column sorted differently in the two plugins. Both cores now share one strict decimal grammar; NaN keys are impossible.strtodhonorsLC_NUMERIC, so a comma-decimal host locale parsed1.5as1. Pinned to the C locale via_strtod_l.Parity
+0/-0tie-break; mirrored byte-for-byte in IdeaMarkdownTableEditor.Tests
🤖 Generated with Claude Code