sparklemotion / nokogiri

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.

Home Page:https://nokogiri.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] DTD Validation fails with HTTPS DTD

jessebs opened this issue · comments

DTD Validation fails with https urls.

This script recreates:

#! /usr/bin/env ruby

require 'nokogiri'

xml = '<?xml version="1.0"?>
<!DOCTYPE coverage SYSTEM "https://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="1.0" branch-rate="0" lines-covered="2" lines-valid="2" branches-covered="0" branches-valid="0" complexity="0" version="0" timestamp="1636204971">
  <sources>
    <source>/sourcedir/test</source>
  </sources>
  <packages>
    <package name="test" line-rate="1.0" branch-rate="0" complexity="0">
      <classes>
        <class name="test_class" filename="test_class.rb" line-rate="1.0" branch-rate="0" complexity="0">
          <methods/>
          <lines>
            <line number="1" branch="false" hits="1"/>
            <line number="2" branch="false" hits="2"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>'
options = Nokogiri::XML::ParseOptions::DTDLOAD
doc = Nokogiri::XML::Document.parse(xml, nil, nil, options)
puts "Errors: #{doc.errors}"

Gives the error:

Errors: [#<Nokogiri::XML::SyntaxError: failed to load external entity "https://cobertura.sourceforge.net/xml/coverage-04.dtd">]

Environment

# Nokogiri (1.5.11)
    ---
    warnings: []
    nokogiri: 1.5.11
    ruby:
      version: 3.1.1
      platform: arm64-darwin21
      description: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]
      engine: ruby
    libxml:
      binding: extension
      compiled: 2.9.13
      loaded: 2.9.13

Hi! Thanks for opening this issue. I found that you've also opened a duplicate issue upstream with libxml2 at https://gitlab.gnome.org/GNOME/libxml2/-/issues/693 and have seend that it's a duplicate of an old issue described at https://gitlab.gnome.org/GNOME/libxml2/-/issues/160, so I'm going to close this.

In the future, when opening the same issue against multiple projects, please consider closing the duplicates yourself when you find an answer, so that maintainers don't spend time duplicating effort.