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 - handle unencoded urls coming from API #612

Merged
merged 4 commits into from
Sep 15, 2023
Merged

Conversation

mormaer
Copy link
Collaborator

@mormaer mormaer commented Sep 15, 2023

Checklist

Pull Request Information

About this Pull Request

This PR resolves an issue found on lemmy.world (but would happen on any instance) that caused our modelling to fail when the API returns a URL which is not percent encoded.

There is a stickied post at the top of the lemmy.world all feed including a link to their Matrix space (https://matrix.to/#/#space:lemmy.world) The #'s here are not percent encoded and so trying to form it into a URL makes Swift unhappy 🙈

The change in this PR introduces a new LemmyURL struct which will attempt to form a URL from the supplied string without any changes, if that process fails it will apply percent encoding and re-try. If the second step fails, it will fail the decoding as before.

I've gone through and changed the places where we were previously modelling values as URL/URL? in the API to now decode the raw String/String? values and then added computed properties which use the new struct to create the url when requested.

I have not adjusted the .actorId values and have left those as URL for now. We could alter those to work in the same way, but I do not expect (famous last words) Lemmy to return urls that require percent encoding within that value.

Given the above about the .actorId, applying this fix across all of the various URLs is likely being over-cautious but this way we are protected should any unencoded URLs sneak through in other calls.

Screenshots and Videos

This shows the result before and after the fix is applied.

BORKED UNBORKED
broken.mp4
working.mp4

@mormaer mormaer requested a review from a team as a code owner September 15, 2023 16:13
@mormaer mormaer requested review from JakeShirley and ShadowJonathan and removed request for a team September 15, 2023 16:13
@mormaer mormaer merged commit 6911243 into dev Sep 15, 2023
4 checks passed
@mormaer mormaer deleted the fix-handle_unencoded_urls branch September 15, 2023 20:41
boscojwho pushed a commit to boscojwho/mlem that referenced this pull request Sep 16, 2023
mormaer added a commit that referenced this pull request Sep 17, 2023
@mormaer mormaer mentioned this pull request Sep 17, 2023
mormaer added a commit that referenced this pull request Sep 17, 2023
EricBAndrews pushed a commit that referenced this pull request Sep 17, 2023
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