Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-53799] Stop autocompleting while the user is typing https:// #3202

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/app/serverViewState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,38 @@ describe('app/serverViewState', () => {
expect(result.validatedURL).toBe('https://server.com/');
});

it('should not update the URL if the user is typing https://', async () => {
let result = await serverViewState.handleServerURLValidation({}, 'h');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'ht');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'htt');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'http');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'HTTP');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'https');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'HTTPS');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'https:');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'https:/');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'https://');
expect(result.status).toBe(URLValidationStatus.Invalid);
result = await serverViewState.handleServerURLValidation({}, 'https://a');
expect(result.status).toBe(URLValidationStatus.OK);
});

it('should update the URL if the user is typing something other than http', async () => {
let result = await serverViewState.handleServerURLValidation({}, 'abchttp');
expect(result.status).toBe(URLValidationStatus.OK);
result = await serverViewState.handleServerURLValidation({}, 'abchttps');
expect(result.status).toBe(URLValidationStatus.OK);
});

it('should attempt HTTP when HTTPS fails, and generate a warning', async () => {
ServerInfo.mockImplementation(({url}) => ({
fetchConfigData: jest.fn().mockImplementation(() => {
Expand Down Expand Up @@ -477,7 +509,7 @@ describe('app/serverViewState', () => {

const result = await serverViewState.handleServerURLValidation({}, 'https://not-server.com');
expect(result.status).toBe(URLValidationStatus.NotMattermost);
expect(result.validatedURL).toBe('https://not-server.com/');
expect(result.validatedURL).toBe('https://not-server.com');
});

it('should update the users URL when the Site URL is different', async () => {
Expand Down
11 changes: 6 additions & 5 deletions src/app/serverViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ export class ServerViewState {

let httpUrl = url;
if (!isValidURL(url)) {
// If it already includes the protocol, tell them it's invalid
if (isValidURI(url)) {
// If it already includes the protocol, force it to HTTPS
if (isValidURI(url) && !url.toLowerCase().startsWith('http')) {
httpUrl = url.replace(/^((.+):\/\/)?/, 'https://');
} else {
// Otherwise add HTTPS for them
} else if (!'https://'.startsWith(url.toLowerCase()) && !'http://'.startsWith(url.toLowerCase())) {
// Check if they're starting to type `http(s)`, otherwise add HTTPS for them
httpUrl = `https://${url}`;
}
}
Expand Down Expand Up @@ -279,8 +279,9 @@ export class ServerViewState {

// If we can't get the remote info, warn the user that this might not be the right URL
// If the original URL was invalid, don't replace that as they probably have a typo somewhere
// Also strip the trailing slash if it's there so that the user can keep typing
if (!remoteInfo) {
return {status: URLValidationStatus.NotMattermost, validatedURL: parsedURL.toString()};
return {status: URLValidationStatus.NotMattermost, validatedURL: parsedURL.toString().replace(/\/$/, '')};
}

const remoteServerName = remoteInfo.siteName === 'Mattermost' ? remoteURL.host.split('.')[0] : remoteInfo.siteName;
Expand Down
Loading