[openstreetmap/openstreetmap-website] No checks for relation members in API (Issue #3563)

Jochen Topf notifications at github.com
Mon Jun 6 09:12:35 UTC 2022


### URL

_No response_

### How to reproduce the issue?

The API checks tag keys and values for the 255 characters max length ([for instance for nodes](https://github.com/openstreetmap/openstreetmap-website/blob/master/test/models/node_tag_test.rb)) and for some [invalid characters](https://github.com/openstreetmap/openstreetmap-website/blob/master/test/validators/characters_validator_test.rb#L30-L41). This check is not done for roles as far as I can see. Cgimap [does the length test](https://github.com/zerebubuth/openstreetmap-cgimap/blob/master/test/test_parse_osmchange_input.cpp#L838-L865), not sure about the character test.

I validate this, I added these to `test/models/relation_member_test.rb` and then the tests fail:
```
 class RelationMemberTest < ActiveSupport::TestCase
  def test_role_with_invalid_characters
    invalid = ["\x7f<hr/>", "test at example.com\x0e-", "s/\x1ff", "aa/\ufffe",
               "aa\x0b-,", "aa?\x08", "/;\uffff.,?", "\x0c#ping",
               "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
    relation = create(:relation)
    node = create(:node)
    invalid.each do |r|
        member = create(:relation_member, :relation => relation, :member => node, :member_role => r)
        assert_not member.valid?, "'#{r}' should not be valid"
        assert_predicate member.errors[:member_role], :any?
    end
  end

  def test_role_too_long
    relation = create(:relation)
    node = create(:node)
    member = create(:relation_member, :relation => relation, :member => node, :member_role => "r" * 256)
    assert_not member.valid?, "Role should be too long"
    assert_predicate member.errors[:member_role], :any?
  end
 end
```

### Screenshot(s) or anything else?

_No response_

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/3563
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/3563 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20220606/e84f155f/attachment.htm>


More information about the rails-dev mailing list