From: Shaun McDonald Date: Fri, 28 Nov 2008 17:38:23 +0000 (+0000) Subject: better handling of duplicate tags. Extra validation in the tests. X-Git-Tag: live~7601^2~121 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/6e98e324e58f67b62c6abf343d60ae5e6f22f9eb?ds=sidebyside better handling of duplicate tags. Extra validation in the tests. --- diff --git a/app/models/node.rb b/app/models/node.rb index e1ad818dd..b2650b61d 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -71,8 +71,8 @@ class Node < ActiveRecord::Base doc.find('//osm/node').each do |pt| return Node.from_xml_node(pt, create) end - rescue - return nil + rescue LibXML::XML::Error => ex + raise OSM::APIBadXMLError.new("node", xml, ex.message) end end @@ -274,7 +274,7 @@ class Node < ActiveRecord::Base # duplicate tags are now forbidden, so we can't allow values # in the hash to be overwritten. - raise OSM::APIDuplicateTagsError.new if @tags.include? k + raise OSM::APIDuplicateTagsError.new("node", self.id, k) if @tags.include? k @tags[k] = v end diff --git a/app/models/relation.rb b/app/models/relation.rb index 0bdacb5ec..ba27e9d7d 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -209,7 +209,7 @@ class Relation < ActiveRecord::Base # duplicate tags are now forbidden, so we can't allow values # in the hash to be overwritten. - raise OSM::APIDuplicateTagsError.new if @tags.include? k + raise OSM::APIDuplicateTagsError.new("relation", self.id, k) if @tags.include? k @tags[k] = v end diff --git a/app/models/way.rb b/app/models/way.rb index 2071fd559..d4bca19aa 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -34,8 +34,8 @@ class Way < ActiveRecord::Base doc.find('//osm/way').each do |pt| return Way.from_xml_node(pt, create) end - rescue - return nil + rescue LibXML::XML::Error => ex + raise OSM::APIBadXMLError.new("relation", xml, ex.message) end end @@ -182,7 +182,7 @@ class Way < ActiveRecord::Base # duplicate tags are now forbidden, so we can't allow values # in the hash to be overwritten. - raise OSM::APIDuplicateTagsError.new if @tags.include? k + raise OSM::APIDuplicateTagsError.new("way", self.id, k) if @tags.include? k @tags[k] = v end diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index 9e5621f8b..9d7f48ca4 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -194,7 +194,8 @@ class NodeControllerTest < ActionController::TestCase content node_xml put :update, :id => current_nodes(:visible_node).id assert_response :bad_request, - "adding duplicate tags to a node should fail with 'bad request'" + "adding duplicate tags to a node should fail with 'bad request'" + assert_equal "Element node/#{current_nodes(:visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}.", @response.body end # test whether string injection is possible diff --git a/test/functional/way_controller_test.rb b/test/functional/way_controller_test.rb index fcd1557d1..40ac0bd71 100644 --- a/test/functional/way_controller_test.rb +++ b/test/functional/way_controller_test.rb @@ -219,6 +219,7 @@ class WayControllerTest < ActionController::TestCase put :update, :id => current_ways(:visible_way).id assert_response :bad_request, "adding a duplicate tag to a way should fail with 'bad request'" + assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}.", @response.body end ## @@ -243,6 +244,7 @@ class WayControllerTest < ActionController::TestCase put :update, :id => current_ways(:visible_way).id assert_response :bad_request, "adding new duplicate tags to a way should fail with 'bad request'" + assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key i_am_a_duplicate.", @response.body end ## @@ -264,6 +266,7 @@ class WayControllerTest < ActionController::TestCase put :create assert_response :bad_request, "adding new duplicate tags to a way should fail with 'bad request'" + assert_equal "Element way/ has duplicate tags with key addr:housenumber.", @response.body end ##