@@ -28,6 +28,8 @@ enum ValidationError {
28
28
Empty = 0 ,
29
29
InvalidUrl = 1 ,
30
30
NoUseEmail = 2 ,
31
+ UnsupportedSchemeZulip = 3 ,
32
+ UnsupportedSchemeOther = 4 ,
31
33
}
32
34
33
35
function validationErrorMsg ( validationError : ValidationError ) : LocalizableText {
@@ -38,6 +40,11 @@ function validationErrorMsg(validationError: ValidationError): LocalizableText {
38
40
return 'Please enter a valid URL.' ;
39
41
case ValidationError . NoUseEmail :
40
42
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://.' ;
41
48
}
42
49
}
43
50
@@ -54,6 +61,16 @@ const tryParseInput = (realmInputValue: string): MaybeParsedInput => {
54
61
55
62
let url = tryParseUrl ( trimmedInputValue ) ;
56
63
if ( ! / ^ h t t p s ? : \/ \/ / . 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
+ }
57
74
url = tryParseUrl ( `https://${ trimmedInputValue } ` ) ;
58
75
}
59
76
0 commit comments