mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-21 11:30:38 -07:00
Properly parse at-commands with narrow non-breaking spaces (#18677)
This commit is contained in:
committed by
GitHub
parent
cc2798018b
commit
eb94284256
@@ -134,6 +134,14 @@ describe('parseInputForHighlighting', () => {
|
||||
{ text: '@/my\\ path/file.txt', type: 'file' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should highlight a file path with narrow non-breaking spaces (NNBSP)', () => {
|
||||
const text = 'cat @/my\u202Fpath/file.txt';
|
||||
expect(parseInputForHighlighting(text, 0)).toEqual([
|
||||
{ text: 'cat ', type: 'default' },
|
||||
{ text: '@/my\u202Fpath/file.txt', type: 'file' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseInputForHighlighting with Transformations', () => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { LRUCache } from 'mnemonist';
|
||||
import { cpLen, cpSlice } from './textUtils.js';
|
||||
import { LRU_BUFFER_PERF_CACHE_LIMIT } from '../constants.js';
|
||||
import { AT_COMMAND_PATH_REGEX_SOURCE } from '../hooks/atCommandProcessor.js';
|
||||
|
||||
export type HighlightToken = {
|
||||
text: string;
|
||||
@@ -19,11 +20,12 @@ export type HighlightToken = {
|
||||
|
||||
// Matches slash commands (e.g., /help), @ references (files or MCP resource URIs),
|
||||
// and large paste placeholders (e.g., [Pasted Text: 6 lines]).
|
||||
// The @ pattern uses a negated character class to support URIs like `@file:///example.txt`
|
||||
// which contain colons. It matches any character except delimiters: comma, whitespace,
|
||||
// semicolon, common punctuation, and brackets.
|
||||
//
|
||||
// The @ pattern uses the same source as the command processor to ensure consistency.
|
||||
// It matches any character except strict delimiters (ASCII whitespace, comma, etc.).
|
||||
// This supports URIs like `@file:///example.txt` and filenames with Unicode spaces (like NNBSP).
|
||||
const HIGHLIGHT_REGEX = new RegExp(
|
||||
`(^/[a-zA-Z0-9_-]+|@(?:\\\\ |[^,\\s;!?()\\[\\]{}])+|${PASTED_TEXT_PLACEHOLDER_REGEX.source})`,
|
||||
`(^/[a-zA-Z0-9_-]+|@${AT_COMMAND_PATH_REGEX_SOURCE}|${PASTED_TEXT_PLACEHOLDER_REGEX.source})`,
|
||||
'g',
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user