From 2bcbf25450fe3e02b2eb1869dccd4cdf555aa120 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Wed, 22 Oct 2025 11:55:32 +0100 Subject: [PATCH] Avoid referencing submodule XML directly --- app/controllers/api/user_preferences_controller.rb | 2 +- app/controllers/application_controller.rb | 4 ++-- app/jobs/trace_importer_job.rb | 2 +- app/models/application_record.rb | 2 ++ lib/diff_reader.rb | 2 ++ lib/osm.rb | 6 +++--- test/test_helper.rb | 1 + 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/user_preferences_controller.rb b/app/controllers/api/user_preferences_controller.rb index 9451f849c..f5600b796 100644 --- a/app/controllers/api/user_preferences_controller.rb +++ b/app/controllers/api/user_preferences_controller.rb @@ -35,7 +35,7 @@ module Api new_preferences = {} - doc = XML::Parser.string(request.raw_post, :options => XML::Parser::Options::NOERROR).parse + doc = LibXML::XML::Parser.string(request.raw_post, :options => LibXML::XML::Parser::Options::NOERROR).parse doc.find("//preferences/preference").each do |pt| if preference = old_preferences.delete(pt["k"]) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 758a51beb..536428b9e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -175,8 +175,8 @@ class ApplicationController < ActionController::Base if request.headers["X-Error-Format"]&.casecmp?("xml") result = OSM::API.new.xml_doc result.root.name = "osmError" - result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}") - result.root << (XML::Node.new("message") << message) + result.root << (LibXML::XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}") + result.root << (LibXML::XML::Node.new("message") << message) render :xml => result.to_s else diff --git a/app/jobs/trace_importer_job.rb b/app/jobs/trace_importer_job.rb index 3c8097933..abb14c1b9 100644 --- a/app/jobs/trace_importer_job.rb +++ b/app/jobs/trace_importer_job.rb @@ -12,7 +12,7 @@ class TraceImporterJob < ApplicationJob UserMailer.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver trace.destroy end - rescue XML::Error => e + rescue LibXML::XML::Error => e logger.info e.to_s UserMailer.gpx_failure(trace, e).deliver trace.destroy diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 71fbba5b3..e6952f86a 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base + include LibXML + self.abstract_class = true end diff --git a/lib/diff_reader.rb b/lib/diff_reader.rb index ad3c64a86..0521bc739 100644 --- a/lib/diff_reader.rb +++ b/lib/diff_reader.rb @@ -6,6 +6,8 @@ # Uses the streaming LibXML "Reader" interface to cut down on memory # usage, so hopefully we can process fairly large diffs. class DiffReader + include LibXML + # maps each element type to the model class which handles it MODELS = { "node" => Node, diff --git a/lib/osm.rb b/lib/osm.rb index 1b571b281..879927b1d 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -469,9 +469,9 @@ module OSM class API def xml_doc - doc = XML::Document.new - doc.encoding = XML::Encoding::UTF_8 - root = XML::Node.new "osm" + doc = LibXML::XML::Document.new + doc.encoding = LibXML::XML::Encoding::UTF_8 + root = LibXML::XML::Node.new "osm" xml_root_attributes.each do |k, v| root[k] = v end diff --git a/test/test_helper.rb b/test/test_helper.rb index ae784239c..d9a03fec1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,6 +42,7 @@ module ActiveSupport class TestCase include FactoryBot::Syntax::Methods include ActiveJob::TestHelper + include LibXML # Run tests in parallel with specified workers parallelize(:workers => :number_of_processors) -- 2.39.5