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 a regression from #4235. #4265

Merged
merged 3 commits into from
Sep 22, 2020
Merged

Fix a regression from #4235. #4265

merged 3 commits into from
Sep 22, 2020

Conversation

chrisbobbe
Copy link
Contributor

There was an accidental duplication of the trailing slash on the realm in all API requests, starting in 865914f. So, fix that and make some more progress toward #4146.

`fetchWithAuth`'s implementation is very short, and we don't use it
anywhere except `apiFetch`, so it already seems wise just to inline
it.

We're also about to shorten `apiFetch` by using a URL computation
instead of string concatenation (for zulip#4146), which will make an even
stronger case for inlining `fetchWithAuth`.
@gnprice
Copy link
Member

gnprice commented Sep 22, 2020

Thanks! About to merge.

`isValidUrl` failed to alert us of a double-forward-slash issue in
this string concatenation: the realm gained a trailing slash in its
new spelling as `realm.origin` from 865914f0e, and we kept the
leading slash in what we were adding to the end of the realm. This
is a sign that `isValidUrl` should be retired ASAP; we'll do that in
an upcoming commit.

I think this isn't a problem with isValidUrl (although still good to retire it now that we have URL) -- the resulting URL is a perfectly valid URL, and new URL agrees. It just isn't the URL we intended, and the server doesn't understand it as pointing to the API route we wanted.

$ node
> (new URL('https://example.com//foo///bar')).toString()
'https://example.com//foo///bar'

For zulip#4146, but also to fix a recent regression from 865914f.

The URL constructor already throws a special "Invalid URL" error if
it can't put together a valid URL from the inputs, so, nicely, we
get to remove the `isValidUrl` call site.

There was a double-forward-slash issue in this string concatenation:
the realm gained a trailing slash with the round-trip through
`new URL(…).toString()` from 865914f, and we kept the leading slash
in what we were adding to the end of the realm.
And use a URL computation instead, which is what we do elsewhere. In
particular, it's how we check whether we can store the realm in
Redux, so it's good to make the UI align with that. This helper
function is a relic from the days before zulip#4081 and zulip#4146, so it
should disappear anyway.

It was the sole user of an NPM package. So, uninstall that.
@gnprice gnprice merged commit 4ae402c into zulip:master Sep 22, 2020
@chrisbobbe
Copy link
Contributor Author

Thanks for the review and merge!

@gnprice
Copy link
Member

gnprice commented Sep 22, 2020

It seems likely that this line has the same issue, then, in the Apple auth flow:

+    // TODO: Use a `URL` computation, for #4146.
     openLink(`${this.props.realm.toString()}/complete/apple/?${params}`);

@chrisbobbe
Copy link
Contributor Author

Ah, yeah, probably—testing with a fix now.

@chrisbobbe
Copy link
Contributor Author

Ah, yeah, probably—testing with a fix now.

OK, just sent #4266.

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