From f464e2a6e9679636d6ae8dbe7b3448cc4cab334d Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 26 Oct 2016 10:35:03 +0100 Subject: [PATCH] Suppress XML parsing errors. This technique was already used in app/models/changeset.rb This suppresses the error messages when parsing invalid XML, but the exceptions are still raised, as tested in test_from_xml_double_lat in test/models/node_test.rb --- app/controllers/changeset_controller.rb | 2 +- app/controllers/user_preference_controller.rb | 2 +- app/models/node.rb | 2 +- app/models/relation.rb | 2 +- app/models/trace.rb | 2 +- app/models/way.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 09bad34bc..da066a73a 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -83,7 +83,7 @@ class ChangesetController < ApplicationController # the request is in pseudo-osm format... this is kind-of an # abuse, maybe should change to some other format? - doc = XML::Parser.string(request.raw_post).parse + doc = XML::Parser.string(request.raw_post, :options => XML::Parser::Options::NOERROR).parse doc.find("//osm/node").each do |n| lon << n["lon"].to_f * GeoRecord::SCALE lat << n["lat"].to_f * GeoRecord::SCALE diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preference_controller.rb index 78ab45308..bf9bab213 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preference_controller.rb @@ -39,7 +39,7 @@ class UserPreferenceController < ApplicationController new_preferences = {} - doc = XML::Parser.string(request.raw_post).parse + doc = XML::Parser.string(request.raw_post, :options => XML::Parser::Options::NOERROR).parse doc.find("//preferences/preference").each do |pt| if preference = old_preferences.delete(pt["k"]) diff --git a/app/models/node.rb b/app/models/node.rb index 578735688..2a64259c1 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -49,7 +49,7 @@ class Node < ActiveRecord::Base # Read in xml as text and return it's Node object representation def self.from_xml(xml, create = false) - p = XML::Parser.string(xml) + p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse doc.find("//osm/node").each do |pt| diff --git a/app/models/relation.rb b/app/models/relation.rb index 4c80be210..ed37d159a 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -36,7 +36,7 @@ class Relation < ActiveRecord::Base TYPES = %w(node way relation).freeze def self.from_xml(xml, create = false) - p = XML::Parser.string(xml) + p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse doc.find("//osm/relation").each do |pt| diff --git a/app/models/trace.rb b/app/models/trace.rb index 85c0244d5..47e5c38b7 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -174,7 +174,7 @@ class Trace < ActiveRecord::Base # Read in xml as text and return it's Node object representation def self.from_xml(xml, create = false) - p = XML::Parser.string(xml) + p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse doc.find("//osm/gpx_file").each do |pt| diff --git a/app/models/way.rb b/app/models/way.rb index ecbdd2f9c..98c4902f9 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -34,7 +34,7 @@ class Way < ActiveRecord::Base # Read in xml as text and return it's Way object representation def self.from_xml(xml, create = false) - p = XML::Parser.string(xml) + p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse doc.find("//osm/way").each do |pt| -- 2.43.2