Skip to content

Commit 107e1ed

Browse files
committed
Validate api url before using
1 parent 62b2bcb commit 107e1ed

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ export class Options {
329329
return '';
330330
}
331331

332+
// people often accidentally enter their API Key into the API Url settings input
333+
if (!Utils.validateApiUrl(apiUrl)) apiUrl = '';
334+
332335
if (!apiUrl) {
333336
try {
334337
apiUrl = await this.getSettingAsync<string>('settings', 'api_url');

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export class Utils {
3030
return '';
3131
}
3232

33+
public static validateApiUrl(url: string): string {
34+
if (!url) return '';
35+
if (url.startsWith('http://') || url.startsWith('https://')) return url.trim();
36+
return '';
37+
}
38+
3339
public static validateProxy(proxy: string): string {
3440
if (!proxy) return '';
3541
let re;

src/wakatime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export class WakaTime {
256256
placeHolder: 'https://api.wakatime.com/api/v1',
257257
value: apiUrl,
258258
ignoreFocusOut: true,
259+
validateInput: Utils.validateApiUrl.bind(this),
259260
};
260261
vscode.window.showInputBox(promptOptions).then((val) => {
261262
if (val) {

0 commit comments

Comments
 (0)