From c3f1fc851608d8a3a1e80faefd979e50357b2697 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Wed, 7 Dec 2016 12:40:38 -0800 Subject: [PATCH] Exclude port (#16680) --- .../services/telemetry/common/workspaceStats.ts | 4 ++-- .../services/telemetry/test/workspaceStats.test.ts | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/services/telemetry/common/workspaceStats.ts b/src/vs/workbench/services/telemetry/common/workspaceStats.ts index 2fc5ad6967a..9eaf8f38d97 100644 --- a/src/vs/workbench/services/telemetry/common/workspaceStats.ts +++ b/src/vs/workbench/services/telemetry/common/workspaceStats.ts @@ -17,7 +17,7 @@ import { IOptions } from 'vs/workbench/common/options'; const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/; -const SecondLevelDomainMatcher = /[^@.]+\.[^.]+$/; +const SecondLevelDomainMatcher = /([^@:.]+\.[^@:.]+)(:\d+)?$/; const RemoteMatcher = /^\s*url\s*=\s*(.+\S)\s*$/mg; type Tags = { [index: string]: boolean | number }; @@ -142,7 +142,7 @@ export class WorkspaceStats { private stripLowLevelDomains(domain: string): string { let match = domain.match(SecondLevelDomainMatcher); - return match ? match[0] : null; + return match ? match[1] : null; } private extractDomain(url: string): string { diff --git a/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts b/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts index eece429b804..0b2ecad172d 100644 --- a/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts +++ b/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts @@ -14,8 +14,10 @@ suite('Telemetry - WorkspaceStats', () => { const stats = new WorkspaceStats(null, null, null); assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://github.com/Microsoft/vscode.git')), ['github.com']); assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://git.example.com/gitproject.git')), ['example.com']); - assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://username@github.com/username/repository.git')), ['github.com']); - assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://username:password@github.com/username/repository.git')), ['github.com']); + assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://username@github2.com/username/repository.git')), ['github2.com']); + assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://username:password@github3.com/username/repository.git')), ['github3.com']); + assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://username:password@example2.com:1234/username/repository.git')), ['example2.com']); + assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('https://example3.com:1234/username/repository.git')), ['example3.com']); }); test('SSH remotes', function () { @@ -27,7 +29,7 @@ suite('Telemetry - WorkspaceStats', () => { const stats = new WorkspaceStats(null, null, null); assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('git@github.com:Microsoft/vscode.git')), ['github.com']); assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('user@git.server.org:project.git')), ['server.org']); - assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('git.server.org:project.git')), ['server.org']); + assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('git.server2.org:project.git')), ['server2.org']); }); test('Local remotes', function () { @@ -36,6 +38,12 @@ suite('Telemetry - WorkspaceStats', () => { assert.deepStrictEqual(stats.getDomainsOfRemotes(remote('file:///opt/git/project.git')), []); }); + test('Multiple remotes', function () { + const stats = new WorkspaceStats(null, null, null); + const config = ['https://github.com/Microsoft/vscode.git', 'https://git.example.com/gitproject.git'].map(remote).join(''); + assert.deepStrictEqual(stats.getDomainsOfRemotes(config).sort(), ['example.com', 'github.com']); + }); + function remote(url: string): string { return `[remote "origin"] url = ${url} -- GitLab