Skip to content

Commit de3c62c

Browse files
chrisbobbegnprice
authored andcommitted
RealmInputScreen: Add unsupported-scheme validation errors
1 parent 581ba42 commit de3c62c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/start/RealmInputScreen.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ enum ValidationError {
2828
Empty = 0,
2929
InvalidUrl = 1,
3030
NoUseEmail = 2,
31+
UnsupportedSchemeZulip = 3,
32+
UnsupportedSchemeOther = 4,
3133
}
3234

3335
function validationErrorMsg(validationError: ValidationError): LocalizableText {
@@ -38,6 +40,11 @@ function validationErrorMsg(validationError: ValidationError): LocalizableText {
3840
return 'Please enter a valid URL.';
3941
case ValidationError.NoUseEmail:
4042
return 'Please enter the server URL, not your email.';
43+
case ValidationError.UnsupportedSchemeZulip:
44+
// TODO: What would be more helpful here? (First, maybe find out what
45+
// leads people to try a "zulip://" URL, if anyone actually does that)
46+
case ValidationError.UnsupportedSchemeOther: // eslint-disable-line no-fallthrough
47+
return 'The server URL must start with http:// or https://.';
4148
}
4249
}
4350

@@ -54,6 +61,16 @@ const tryParseInput = (realmInputValue: string): MaybeParsedInput => {
5461

5562
let url = tryParseUrl(trimmedInputValue);
5663
if (!/^https?:\/\//.test(trimmedInputValue)) {
64+
if (url && url.protocol === 'zulip:') {
65+
// Someone might get the idea to try one of the "zulip://" URLs that
66+
// are discussed sometimes.
67+
// TODO(?): Log to Sentry. How much does this happen, if at all? Maybe
68+
// log once when the input enters this error state, but don't spam
69+
// on every keystroke/render while it's in it.
70+
return { valid: false, error: ValidationError.UnsupportedSchemeZulip };
71+
} else if (url && url.protocol !== 'http:' && url.protocol !== 'https:') {
72+
return { valid: false, error: ValidationError.UnsupportedSchemeOther };
73+
}
5774
url = tryParseUrl(`https://${trimmedInputValue}`);
5875
}
5976

static/translations/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"Please enter a URL.": "Please enter a URL.",
133133
"Please enter a valid URL.": "Please enter a valid URL.",
134134
"Please enter the server URL, not your email.": "Please enter the server URL, not your email.",
135+
"The server URL must start with http:// or https://.": "The server URL must start with http:// or https://.",
135136
"Wrong email or password. Try again.": "Wrong email or password. Try again.",
136137
"Wrong username or password. Try again.": "Wrong username or password. Try again.",
137138
"Enter a valid email address": "Enter a valid email address",

0 commit comments

Comments
 (0)