Skip to content

Commit 1bf3877

Browse files
MeherSruMEHER SRUJANA MATCHA
andauthored
Fix #3874: preserve escaped commas in snippet literals (#4436)
* Fix #3874: preserve escaped commas in snippet literals * Add test for #3874 snippet escaping --------- Co-authored-by: MEHER SRUJANA MATCHA <mehersrujana.matcha@ibm.com>
1 parent 10040c1 commit 1bf3877

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,8 @@ function registerRestartJavaLanguageServerCommand(context: ExtensionContext) {
13251325
}));
13261326
}
13271327

1328-
function escapeSnippetLiterals(value: string): string {
1328+
export function escapeSnippetLiterals(value: string): string {
13291329
return value
1330-
.replace(/\\/g, '\\\\') // Escape backslashes
1330+
.replace(/\\(?!,)/g, '\\\\') // Escape backslashes, but preserve escaped commas
13311331
.replace(/\$(?!\{)/g, '\\$'); // Escape $ only if NOT followed by {
13321332
}

test/standard-mode-suite/extension.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Commands } from '../../src/commands';
77
import * as java from '../../src/javaServerStarter';
88
import * as plugin from '../../src/plugin';
99
import * as requirements from '../../src/requirements';
10+
import { escapeSnippetLiterals } from '../../src/extension';
1011

1112
suite('Java Language Extension - Standard', () => {
1213

@@ -233,4 +234,10 @@ suite('Java Language Extension - Standard', () => {
233234
assert(java.hasDebugFlag(['foo', '--debug=1234']));
234235
assert(java.hasDebugFlag(['foo', '--debug-brk=1234']));
235236
});
237+
238+
test('should preserve escaped commas in code action snippets', () => {
239+
const snippet = '${1|HashMap<Integer\\,Integer>,Map<Integer\\,Integer>|} ${2:x} = new HashMap<Integer, Integer>();';
240+
241+
assert.equal(escapeSnippetLiterals(snippet), snippet);
242+
});
236243
});

0 commit comments

Comments
 (0)