From: Michael Smith Date: Wed, 15 Jun 2005 10:56:18 +0000 (+0000) Subject: Escape angle brackets and square brackets in doctype X-Git-Tag: release/1.79.1~6^2~3419 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a47dfa04feee974f73e678a8a25a9035c355254;p=docbook-dsssl Escape angle brackets and square brackets in doctype declaration/subset. --- diff --git a/contrib/tools/cloak/cloak b/contrib/tools/cloak/cloak index 83d4f3ddc..d84a83ed6 100755 --- a/contrib/tools/cloak/cloak +++ b/contrib/tools/cloak/cloak @@ -33,9 +33,21 @@ my $lines = <$handle>; # if the document has already been cloaked, uncloak it if ($lines =~ m/$comment/ || $0 =~ m/uncloak/) { - $lines =~ s/<\?$comment \?>//; # remove comment added by cloak - $lines =~ s/<\?ENT_ (.*?)_ENT\?>/$1/g; # uncloak all cloaked entities - $lines =~ s/\?DOCTYPE(.*)_END_SUBSET\?/!DOCTYPE$1/s; # uncloak DOCTYPE, subset +# NOTE: We do [\?]+ intead of just \? because some tools (osx +# and/or sgml2xml, for one) add an extra question mark in PIs +# during processing (because SGML PI syntax is different than XML +# PI syntax in that SGML PIs don't have the closing question mark + + $lines =~ s/<\?$comment [\?]+>//; # remove comment added by cloak + $lines =~ s/<\?ENT_ (.*?)_ENT[\?]+>/$1/g; # uncloak all cloaked entities + if ($lines =~ /<\?DOCTYPE(.*)_END_SUBSET[\?]+>/s) { + $doctype = $1; + $doctype =~ s/xxLESS_THANxx//sg; + $doctype =~ s/xxLEFT_SQUARE_BRACKETxx/[/sg; + $doctype =~ s/xxRIGHT_SQUARE_BRACKETxx/]/sg; + $lines =~ s/\?DOCTYPE(.*)_END_SUBSET[\?]+>/!DOCTYPE$doctype>\n/s; # uncloak DOCTYPE, subset + } } else { @@ -55,11 +67,16 @@ if ($lines =~ m/$comment/ || $0 =~ m/uncloak/) { # test to see if there is an internal subset or not, then # cloak DOCTYPE declaration and internal subset (if there is one) - if ($lines =~ //s) { - $lines =~ s//<\?DOCTYPE$1_END_SUBSET\?>/s + if ($lines =~ //s) { + $doctype = $1; + $doctype =~ s/\[/xxLEFT_SQUARE_BRACKETxx/sg; + $doctype =~ s/\]/xxRIGHT_SQUARE_BRACKETxx/sg; + $doctype =~ s/>/xxGREATER_THANxx/sg; + $doctype =~ s//<\?$doctype\_END_SUBSET\?>/s } else { - $lines =~ s/]*)>/<\?DOCTYPE$1_END_SUBSET\?>/s + $lines =~ s/]*)>/<\?DOCTYPE$1_END_SUBSET\?>/s; } }