From 839f2549718e0a5f0978ca11727eeb2f87db359f Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Tue, 26 Nov 2019 15:24:26 +0900 Subject: [PATCH] warn empty prefix for namespace (#128) --- src/xpath.jl | 4 +++- test/runtests.jl | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/xpath.jl b/src/xpath.jl index b6b6495..7ec5fa0 100644 --- a/src/xpath.jl +++ b/src/xpath.jl @@ -81,7 +81,9 @@ function Base.findall(xpath::AbstractString, node::Node, ns=namespaces(node)) throw_xml_error() end for (prefix, uri) in ns - if !isempty(prefix) + if isempty(prefix) + @warn "ignored the empty prefix for '$(uri)'; expected to be non-empty" + else ret = register_namespace!(context_ptr, prefix, uri) @assert ret == 0 end diff --git a/test/runtests.jl b/test/runtests.jl index 93fa25a..9cf40a5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1287,8 +1287,9 @@ end GO:0000001 """) - @test isempty(findall("term", root(doc))) - @test isempty(findall("./term", root(doc))) + warnmsg = "ignored the empty prefix for 'http://www.geneontology.org/dtds/go.dtd#'; expected to be non-empty" + @test isempty(@test_logs (:warn, warnmsg) findall("term", root(doc))) + @test isempty(@test_logs (:warn, warnmsg) findall("./term", root(doc))) @test findall("go:term", root(doc), ["go" => "http://www.geneontology.org/dtds/go.dtd#"]) == elements(root(doc)) @test findall("./go:term", root(doc), ["go" => "http://www.geneontology.org/dtds/go.dtd#"]) == elements(root(doc))