Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that @check always clear error stack. #186

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ function parsehtml(htmlstring::AbstractString)
Ptr{_Node},
(Cstring, Cint, Cstring, Cstring, Cint),
htmlstring, sizeof(htmlstring), url, encoding, options) != C_NULL
show_warnings()
return Document(doc_ptr)
end

Expand Down Expand Up @@ -172,7 +171,6 @@ function readhtml(filename::AbstractString)
Ptr{_Node},
(Cstring, Cstring, Cint),
filename, encoding, options) != C_NULL
show_warnings()
return Document(doc_ptr)
end

Expand All @@ -193,7 +191,6 @@ function readhtml(input::IO)
Ptr{_Node},
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Cstring, Cint),
readcb, closecb, context, uri, encoding, options) != C_NULL
show_warnings()
return Document(doc_ptr)
end

Expand Down
3 changes: 3 additions & 0 deletions src/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ macro check(ex)
if !$(ex)
throw_xml_error()
end
if !isempty(XML_GLOBAL_ERROR_STACK)
show_warnings()
end
ret
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ end
@test version(doc) == "1.0"
@test hasencoding(doc)
@test encoding(doc) == "UTF-8"

# handle invalid xmlns
invalid_xmlns = joinpath(dirname(@__FILE__), "sample1.invalid_xmlns.xml")
doc, messages = capture_logging_messages() do
readxml(invalid_xmlns)
end
@test isa(doc, EzXML.Document)
@test occursin("Warning: XMLError: xmlns: URI This.is.invalid is not absolute from XML Namespace module (code: 100, line: 2)", messages)
@test isempty(EzXML.XML_GLOBAL_ERROR_STACK)
end

@testset "HTML" begin
Expand Down
12 changes: 12 additions & 0 deletions test/sample1.invalid_xmlns.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<story xmlns="This.is.invalid">
<storyinfo>
<author>John Fleck</author>
<datewritten>June 2, 2002</datewritten>
<keyword>example keyword</keyword>
</storyinfo>
<body>
<headline>This is the headline</headline>
<para>This is the body text.</para>
</body>
</story>
Loading