Skip to content

Commit 7603181

Browse files
authored
codewhisperer: remove trailing / or # from startUrl #3612
This is for the consistency of such value for telemetry
1 parent 9da2042 commit 7603181

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/codewhisperer/util/authUtil.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ export class AuthUtil {
6666
} else {
6767
this.usingEnterpriseSSO = false
6868
}
69-
TelemetryHelper.instance.startUrl = isSsoConnection(this.conn) ? this.conn?.startUrl : undefined
69+
// Reformat the url to remove any trailing '/' and `#`
70+
// e.g. https://view.awsapps.com/start/# will become https://view.awsapps.com/start
71+
TelemetryHelper.instance.startUrl = isSsoConnection(this.conn)
72+
? this.reformatStartUrl(this.conn?.startUrl)
73+
: undefined
7074
await Promise.all([
7175
vscode.commands.executeCommand('aws.codeWhisperer.refresh'),
7276
vscode.commands.executeCommand('aws.codeWhisperer.refreshRootNode'),
@@ -78,6 +82,10 @@ export class AuthUtil {
7882
})
7983
}
8084

85+
public reformatStartUrl(startUrl: string | undefined) {
86+
return !startUrl ? undefined : startUrl.replace(/[\/#]+$/g, '')
87+
}
88+
8189
// current active cwspr connection
8290
public get conn() {
8391
return this.secondaryAuth.activeConnection

src/test/codewhisperer/util/authUtil.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ describe('AuthUtil', async function () {
134134
assert.strictEqual(authUtil.conn.ssoRegion, upgradeableConn.ssoRegion)
135135
assert.strictEqual((await auth.listConnections()).filter(isSsoConnection).length, 1)
136136
})
137+
138+
it('test reformatStartUrl should remove trailing slash and hash', function () {
139+
const expected = 'https://view.awsapps.com/start'
140+
assert.strictEqual(authUtil.reformatStartUrl(expected + '/'), expected)
141+
assert.strictEqual(authUtil.reformatStartUrl(undefined), undefined)
142+
assert.strictEqual(authUtil.reformatStartUrl(expected + '/#'), expected)
143+
assert.strictEqual(authUtil.reformatStartUrl(expected + '#/'), expected)
144+
assert.strictEqual(authUtil.reformatStartUrl(expected + '/#/'), expected)
145+
assert.strictEqual(authUtil.reformatStartUrl(expected + '####'), expected)
146+
})
137147
})

0 commit comments

Comments
 (0)