Skip to content

Commit

Permalink
Detect HTML mode in Dtd load/parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Nov 15, 2024
1 parent 7bcce35 commit 4096c1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/LibXML/Dtd.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ multi method new($external-id, $system-id, *%c) {
=end pod

has LibXML::Parser::Context $!parser-ctx;
method !parser-ctx(Bool :$local-errors = False) {
(self.defined ?? $!parser-ctx !! my $) //= self.create: LibXML::Parser::Context, :raw(xmlParserCtxt.new), local-errors => $.config.version >= v2.14.0
method !parser-ctx(Bool :$html) {
my $raw = ($html ?? htmlParserCtxt !! xmlParserCtxt).new;
my $local-errors = $.config.version >= v2.14.0;
(self.defined ?? $!parser-ctx !! my $) //= self.create: LibXML::Parser::Context, :$raw, :$local-errors;
}

multi method parse(Str :$string!, xmlEncodingStr:D :$enc = 'UTF-8', Str :$external-id, Str :$system-id) is hidden-from-backtrace {
Expand Down Expand Up @@ -243,7 +245,8 @@ multi method parse(Str :$string!, xmlEncodingStr:D :$enc = 'UTF-8', Str :$extern


multi method parse(Str :$external-id, Str:D :$system-id!) is hidden-from-backtrace {
my $ctx := self!parser-ctx;
my Bool() $html = xmlDtd::xmlIsXHTML($system-id, $external-id);
my $ctx := self!parser-ctx: :$html;
my xmlDtd:D $raw = $ctx.do: {
if $ctx.local-errors {
my xmlParserInput $input = $ctx.raw.LoadDtd($external-id, $system-id);
Expand Down
1 change: 0 additions & 1 deletion lib/LibXML/Raw.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,6 @@ class xmlDtd is anyNode is export {
method Copy(--> xmlDtd) is native($XML2) is symbol('xmlCopyDtd') {*}
method copy() { $.Copy }

our sub xmlCanonicPath(xmlCharP $systemID --> xmlAllocedStr) is native($XML2) {*}
our sub xmlIsXHTML(xmlCharP $systemID, xmlCharP $publicID --> int32) is native($XML2) {*}
method IsXHTML returns int32 { xmlIsXHTML($!SystemID, $!ExternalID) }
method getAttrDecl(xmlCharP $elem, xmlCharP $name --> xmlAttrDecl) is native($XML2) is symbol('xmlGetDtdAttrDesc') {*}
Expand Down

0 comments on commit 4096c1d

Please sign in to comment.