From 9e52401207acd192ad10782861efdab235458c4c Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 11 Feb 2018 14:08:10 -0800 Subject: [PATCH 1/2] When processing base element or attribute, apply current base to allow for proper relative URI resolution. --- lib/rdf/rdfa/reader/nokogiri.rb | 4 +- lib/rdf/rdfa/reader/rexml.rb | 4 +- spec/reader_spec.rb | 70 +++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/lib/rdf/rdfa/reader/nokogiri.rb b/lib/rdf/rdfa/reader/nokogiri.rb index 02211152..2ac2bded 100644 --- a/lib/rdf/rdfa/reader/nokogiri.rb +++ b/lib/rdf/rdfa/reader/nokogiri.rb @@ -306,10 +306,10 @@ def doc_base(base) case @host_language when :xhtml1, :xhtml5, :html4, :html5 base_el = @doc.at_css("html>head>base") - base = base_el.attribute("href").to_s.split("#").first if base_el + base = base.join(base_el.attribute("href").to_s.split("#").first) if base_el else xml_base = root.attribute_with_ns("base", RDF::XML.to_s) if root - base = xml_base if xml_base + base = base.join(xml_base) if xml_base end base diff --git a/lib/rdf/rdfa/reader/rexml.rb b/lib/rdf/rdfa/reader/rexml.rb index bcd44274..cf317739 100644 --- a/lib/rdf/rdfa/reader/rexml.rb +++ b/lib/rdf/rdfa/reader/rexml.rb @@ -329,10 +329,10 @@ def doc_base(base) case @host_language when :xhtml1, :xhtml5, :html4, :html5 base_el = ::REXML::XPath.first(@doc, "/html/head/base") rescue nil - base = base_el.attribute("href").to_s.split("#").first if base_el + base = base.join(base_el.attribute("href").to_s.split("#").first) if base_el else xml_base = root.attribute("base", RDF::XML.to_s) if root - base = xml_base if xml_base + base = base.join(xml_base) if xml_base end base || @base_uri diff --git a/spec/reader_spec.rb b/spec/reader_spec.rb index 97190624..36075246 100644 --- a/spec/reader_spec.rb +++ b/spec/reader_spec.rb @@ -428,30 +428,58 @@ end end - it "html>head>base" do - html = %( - - - - - Test 0072 - - -

- Learn more by reading the example.org - Example FAQ. -

- - + describe "html>head>base" do + it "uses absolute base" do + html = %( + + + + + Test 0072 + + +

+ Learn more by reading the example.org + Example FAQ. +

+ + + ) + expected = %q( + @prefix dc: . + + dc:title "Example FAQ" . ) - expected = %q( - @prefix dc: . - dc:title "Example FAQ" . - ) + expect(parse(html, base_uri: 'http://example.org/')).to be_equivalent_graph(expected, logger: logger, format: :ttl) + end + + it "uses relative base" do + html = %( + + + + + Test 0072 + + +

+ Learn more by reading the example.org + Example FAQ. +

+ + + ) + expected = %q( + @prefix dc: . - expect(parse(html)).to be_equivalent_graph(expected, logger: logger, format: :ttl) + dc:title "Example FAQ" . + ) + + expect(parse(html, base_uri: 'http://example.org/')).to be_equivalent_graph(expected, logger: logger, format: :ttl) + end end describe "xml:base" do From b3cdfb147f09b0443a1d6a17a58faa3b89527a69 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 11 Feb 2018 14:11:47 -0800 Subject: [PATCH 2/2] Version 3.0.1. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4a36342f..cb2b00e4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0 +3.0.1