[openstreetmap/openstreetmap-website] Add Communities page (#3301)

Andy Allan notifications at github.com
Wed Oct 26 18:46:28 UTC 2022


I worked on the validation topic today, but I don't have something that I'm happy with.

I thought of two approaches. One is to write custom validation code in `ResourceBackend.load`, e.g. that uses a regexp to check the URLs are OK. But then when I started choosing schemes, and doing blank handling, then this feels a bit cludgy since we normally put attribute validation into the models. Reinventing validations feels wrong. If we can declare the validation in the model, then we can do a normal `validates...` declaration instead. So I tried that approach instead, and used the `validate_url` gem too. You can see my commit at https://github.com/gravitystorm/openstreetmap-website/commit/7b5df0daaf7b5a230f180ec914b02db66bfa2fee which I haven't added to this PR.

This threw up some issues:
* FrozenRecord doesn't have anything where it checks validity, nor can I see any way to crowbar that into the loading of each record. So instead I fail loudly during object initialization if there's an invalid URL. This should be fine, in theory, since we'll only update to versions of the node package from time to time, and if there's one with invalid urls then I think it's fine for the tests to fail (and the app to not boot). 
* OCI already contains various schemes, not just http and https but also mailto and xmpp. I wasn't expecting that.
* OCI also contains invalid urls :facepalm: For example, `https://matrix.to/#/#openstreetmap-cat:matrix.org` is [invalid](https://stackoverflow.com/a/26119120/105451) (albeit accepted by browsers) since the `#` isn't permitted inside fragments.

The last of these is a bit of a hard fail for this approach, since we have to deal with what OCI gives us, and this is not a malicious URL and failing to handle it gracefully is not reasonable.

So trying to do things "the right way" hasn't worked as well as I hoped. If anyone has any suggestions to build on this approach then I'm all ears, otherwise my next attempt will be to "reinvent validations" by hand in the `.load` method (sigh).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3301#issuecomment-1292454360
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/3301/c1292454360 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20221026/4f479f4c/attachment.htm>


More information about the rails-dev mailing list