@@ -28,6 +28,8 @@ enum ValidationError {
2828 Empty = 0 ,
2929 InvalidUrl = 1 ,
3030 NoUseEmail = 2 ,
31+ UnsupportedSchemeZulip = 3 ,
32+ UnsupportedSchemeOther = 4 ,
3133}
3234
3335function 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 ( ! / ^ 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+ }
5774 url = tryParseUrl ( `https://${ trimmedInputValue } ` ) ;
5875 }
5976
0 commit comments