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

* [MM-53799] Stop autocompleting while the user is typing `https://`

* PR feedback

* Fix casing issue
This commit is contained in:
Devin Binnie
2024-11-13 12:05:24 -05:00
committed by GitHub
parent 1fe94eb167
commit 453965c964
2 changed files with 39 additions and 6 deletions

View File

@@ -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(() => {
@@ -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 () => {

View File

@@ -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}`;
}
}
@@ -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;