Skip to content

Commit 6caf8c4

Browse files
committed
fix: path anonymization should better deal with paths containing %
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 0c4b74a commit 6caf8c4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/common/utils/telemetryUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
// Regex patterns for path sanitization
88
const NODE_MODULES_REGEX = /[\\\/]?(node_modules|node_modules\.asar)[\\\/]/;
9-
const FILE_REGEX_PATTERN = /(file:\/\/)?([a-zA-Z]:(\\\\|\\|\/)|(\\\\|\\|\/))?([\w-\._]+(\\\\|\\|\/))+[\w-\._]+/g;
9+
const FILE_REGEX_PATTERN = /(file:\/\/?)?([a-zA-Z]:(\\\\|\\|\/)|(\\\\|\\|\/))?([\w-\._%]+(\\\\|\\|\/))+[\w-\._%]+/g;
1010

1111
// Default cleanup patterns to preserve common system/library paths
1212
const DEFAULT_CLEANUP_PATTERNS: RegExp[] = [
1313
/java\.\S*/, // Java standard library and related packages (any non-whitespace chars)
14+
/\/jdt\.ls-java-project\S*/, // Eclipse JDT Language Server Java project paths
1415
];
1516

1617
/**

src/tests/utils/telemetryUtils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ suite('Test anonymizeFilePaths', () => {
166166
assert.strictEqual(result, input);
167167
});
168168

169+
test('should preserve JDT Language Server Java project paths with default patterns', () => {
170+
const input = 'Error at /jdt.ls-java-project/src/main/java/com/example/MyClass.java:45';
171+
const result = anonymizeFilePaths(input);
172+
assert.strictEqual(result, input);
173+
});
174+
175+
test('should anonymize file:/ URLs even with JDT workspace paths', () => {
176+
const input = 'Failed to read package name from file:/Users/someguy/Library/Application%20Support/Code/User/workspaceStorage/4f4553a7f3f79b5e8qa7c889b39fe96b/redhat.java/jdt_ws/Hello.java/';
177+
const result = anonymizeFilePaths(input);
178+
assert.strictEqual(result, 'Failed to read package name from <REDACTED: user-file-path>/');
179+
});
180+
169181
test('should anonymize user paths but preserve Java paths with default patterns', () => {
170182
const input = 'Error at /Users/john/project/src/main.ts:45 and java.base/java.lang.String.<init>(String.java:123)';
171183
const result = anonymizeFilePaths(input);

0 commit comments

Comments
 (0)