# in the hash to be overwritten.
raise OSM::APIDuplicateTagsError.new("node", self.id, k) if @tags.include? k
+ # check tag size here, as we don't create a NodeTag object until
+ # just before we save...
+ raise OSM::APIBadUserInput.new("Node #{self.id} has a tag with too long a key, '#{k}'.") if k.length > 255
+ raise OSM::APIBadUserInput.new("Node #{self.id} has a tag with too long a value, '#{k}'='#{v}'.") if v.length > 255
+
@tags[k] = v
end
# in the hash to be overwritten.
raise OSM::APIDuplicateTagsError.new("relation", self.id, k) if @tags.include? k
+ # check tag size here, as we don't create a RelationTag object until
+ # just before we save...
+ raise OSM::APIBadUserInput.new("Relation #{self.id} has a tag with too long a key, '#{k}'.") if k.length > 255
+ raise OSM::APIBadUserInput.new("Relation #{self.id} has a tag with too long a value, '#{k}'='#{v}'.") if v.length > 255
+
@tags[k] = v
end
# in the hash to be overwritten.
raise OSM::APIDuplicateTagsError.new("way", self.id, k) if @tags.include? k
+ # check tag size here, as we don't create a WayTag object until
+ # just before we save...
+ raise OSM::APIBadUserInput.new("Way #{self.id} has a tag with too long a key, '#{k}'.") if k.length > 255
+ raise OSM::APIBadUserInput.new("Way #{self.id} has a tag with too long a value, '#{k}'='#{v}'.") if v.length > 255
+
@tags[k] = v
end
post :create
assert_response :method_not_allowed
end
-
+
##
# check that the changeset can be read and returns the correct
# document structure.
assert_equal true, Relation.find(current_relations(:visible_relation).id).visible
end
+ ##
+ # upload an element with a really long tag value
+ def test_upload_invalid_too_long_tag
+ basic_authorization users(:public_user).email, "test"
+ cs_id = changesets(:public_user_first_change).id
+
+ # simple diff to create a node way and relation using placeholders
+ diff = <<EOF
+<osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
+ <tag k='foo' v='#{"x"*256}'/>
+ </node>
+ </create>
+</osmChange>
+EOF
+
+ # upload it
+ content diff
+ post :upload, :id => cs_id
+ assert_response :bad_request,
+ "shoudln't be able to upload too long a tag to changeset: #{@response.body}"
+
+ end
+
##
# upload something which creates new objects and inserts them into
# existing containers using placeholders.
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <node lat=\"3.434\" changeset=\"#{changeset.id}\"/>. lon missing", @response.body
+ # test that the upload is rejected when we have a tag which is too long
+ content("<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'><tag k='foo' v='#{'x'*256}'/></node></osm>")
+ put :create
+ assert_response :bad_request, "node upload did not return bad_request status"
+ assert_equal "Node has a tag with too long a value, 'foo'='#{'x'*256}'.", @response.body
+
end
def test_read
# expect failure
assert_response :conflict,
"way upload to closed changeset did not return 'conflict'"
+
+ # create a way with a tag which is too long
+ content "<osm><way changeset='#{open_changeset_id}'>" +
+ "<nd ref='#{nid1}'/>" +
+ "<tag k='foo' v='#{'x'*256}'/>" +
+ "</way></osm>"
+ put :create
+ # expect failure
+ assert_response :bad_request,
+ "way upload to with too long tag did not return 'bad_request'"
end
# -------------------------------------