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

Add get(String) alternative which fails on invalid inputs #4118

Merged
merged 1 commit into from
Jul 6, 2018

Conversation

JakeWharton
Copy link
Collaborator

This is an unchecked-throwing version of parse(String).

Closes #3850. Closes #4032.

throws MalformedURLException, UnknownHostException {
return HttpUrl.getChecked(url);
@Override public boolean isInvalidHttpUrlHost(IllegalArgumentException e) {
return e.getMessage().startsWith(HttpUrl.Builder.INVALID_HOST);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So yeah this is kinda gross, but... whatever. It's only for HttpURLConnection use.

assertEquals(parse("https://host/"), parse("https://host/"));
assertEquals(parse("https://host/"), parse("HTTPS://host/"));

assertInvalid("image640://480.png", "Expected URL scheme 'http' or 'https' but was 'image640'");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh nice.

@JakeWharton JakeWharton force-pushed the jakew/parseOrThrow/2018-07-05 branch from 9be52c7 to 75a467b Compare July 6, 2018 17:56
This is an unchecked-throwing version of parse(String).
@JakeWharton JakeWharton force-pushed the jakew/parseOrThrow/2018-07-05 branch from 75a467b to 351b3d6 Compare July 6, 2018 19:31
@JakeWharton JakeWharton merged commit a2fb46b into master Jul 6, 2018
@JakeWharton JakeWharton deleted the jakew/parseOrThrow/2018-07-05 branch July 6, 2018 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants