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

Fix app crash due to invalid realm URL #2064

Closed
wants to merge 0 commits into from
Closed

Fix app crash due to invalid realm URL #2064

wants to merge 0 commits into from

Conversation

anurag1018
Copy link
Collaborator

A direct match with the acceptable realm URL(comprising of letters, numbers and hyphens) fixes the issue. Displays an error for unacceptable URLs as well as disables the Enter button upon entering invalid URLs.
Fixes #2016

@zulipbot
Copy link
Member

Hello @anurag1018, it seems like you have referenced an issue in your pull request, but you have not referenced that issue in your commit message(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged.

Please run git commit --amend in your command line client to amend your commit message description with "Fixes #{issue number}”.

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51

Thank you for your contributions to Zulip!

Copy link
Contributor

@borisyankov borisyankov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first effort. 👍
Consider my comments and go forward.

@@ -6,6 +6,7 @@ import type { Actions } from '../types';
import connectWithActions from '../connectWithActions';
import { ErrorMsg, Label, SmartUrlInput, Screen, ZulipButton } from '../common';
import { getServerSettings } from '../api';
import { checkUrlValidity } from '../utils/url';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a function is expected to return boolean, we tend to name it in the form of isUserFound, doesFileExist etc. Here it will be isValidUrl

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

@@ -83,6 +85,7 @@ class RealmScreen extends PureComponent<Props, State> {
text="Enter"
progress={progress}
onPress={this.tryRealm}
disabled={!isEnterEnabled}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already check for errors in the tryRealm function.
You can do the check and set an error text.
That will be more clear to the user.

src/utils/url.js Outdated
@@ -156,3 +156,6 @@ export const autoCompleteUrl = (
`${hasProtocol(value) ? '' : protocol}${value || 'your-org'}${
value.indexOf('.') === -1 ? append : !value.match(/.+\..+\.+./g) ? shortAppend : ''
}`;

export const checkUrlValidity = (url: string) =>
/https:\/\/[a-zA-Z0-9-]+.[a-zA-Z0-9-]+.[a-zA-Z]+/.test(url) ? undefined : 'Invalid URL';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While subdomains hosted on zulipchat.com might have this restriction on them that is unlikely the case for self-hosted apps that might have any domain.

Copy link
Collaborator Author

@anurag1018 anurag1018 Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetch api on react-native android has this bug. So if we consider a case where an invalid url is passed, for example special characters are allowed in the subdomain, the app will crash as soon as the fetch is called irrespective of using exception handling.
Ref: facebook/react-native#7436

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially valid URL: 'hey.this.is.long.com' and it does not pass the Regex.

src/utils/url.js Outdated
@@ -156,3 +156,6 @@ export const autoCompleteUrl = (
`${hasProtocol(value) ? '' : protocol}${value || 'your-org'}${
value.indexOf('.') === -1 ? append : !value.match(/.+\..+\.+./g) ? shortAppend : ''
}`;

export const checkUrlValidity = (url: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better that you split the validity check and the error result. Thus this function should return true / false depending on if the url is valid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a great candidate for a unit-test. You should demonstrate via a test both that it catches invalid urls and that it does not incorrectly catch valid urls.

@zulipbot
Copy link
Member

Hello @anurag1018, it seems like you have referenced an issue in your pull request, but you have not referenced that issue in your commit message(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged.

Please run git commit --amend in your command line client to amend your commit message description with "Fixes #{issue number}”.

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51

Thank you for your contributions to Zulip!

@anurag1018 anurag1018 closed this Mar 22, 2018
@gnprice gnprice added the severe: crash The app quits, or stops responding. label Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severe: crash The app quits, or stops responding.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on welcome screen with "unexpected url"
4 participants