Skip to content

fix: restrict case-insensitive search to ASCII - #1159

Closed
noborus wants to merge 2 commits into
masterfrom
restricted-lowercase
Closed

fix: restrict case-insensitive search to ASCII#1159
noborus wants to merge 2 commits into
masterfrom
restricted-lowercase

Conversation

@noborus

@noborus noborus commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Case-insensitive matching previously lowercased the full target string before searching. For some Unicode runes, this changes the byte length of the string, so the returned match offsets no longer point to the original text and can highlight the wrong bytes.

This patch limits case-insensitive matching to ASCII-only input, where lower/upper conversion is byte-stable and safe. Non-ASCII text keeps the existing behavior instead of relying on Unicode lowercasing that can change offset positions.

This is a reference implementation for discussion and is not intended to be merged as-is.

Case-insensitive matching previously lowercased the full target string before
searching. For some Unicode runes, this changes the byte length of the string,
so the returned match offsets no longer point to the original text and can
highlight the wrong bytes.

This patch limits case-insensitive matching to ASCII-only input, where
lower/upper conversion is byte-stable and safe. Non-ASCII text keeps the
existing behavior instead of relying on Unicode lowercasing that can change
offset positions.

This is a reference implementation for discussion and is not intended to be
merged as-is.
- replace expensive strings.ToLower/ToUpper check with ASCII fast-path
- limit lowercase conversion to ASCII alphabetic characters
- add regression tests for case-insensitive detection
@noborus

noborus commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

This changes the behavior, so I decided to close it after all.

@noborus noborus closed this Sep 1, 2026
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.

1 participant