fix - handle unencoded urls coming from API #612
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
- partially addresses * feeds don’t load with latest lemmy version (world et al) #607
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 aURL
makes Swift unhappy 🙈The change in this PR introduces a new
LemmyURL
struct which will attempt to form aURL
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 rawString/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 asURL
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.
broken.mp4
working.mp4