Commit d32e0c13 authored by Martin Waitz's avatar Martin Waitz Committed by Linus Torvalds

[PATCH] docbook: factor out escaping of XML special characters

Factor out escaping of XML special characters
Signed-off-by: default avatarMartin Waitz <tali@admingilde.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent bb445dd4
...@@ -1624,6 +1624,15 @@ sub process_state3_type($$) { ...@@ -1624,6 +1624,15 @@ sub process_state3_type($$) {
} }
} }
# replace <, >, and &
sub xml_escape($) {
shift;
s/\&/\\\\\\amp;/g;
s/\</\\\\\\lt;/g;
s/\>/\\\\\\gt;/g;
return $_;
}
sub process_file($) { sub process_file($) {
my ($file) = "$ENV{'SRCTREE'}@_"; my ($file) = "$ENV{'SRCTREE'}@_";
my $identifier; my $identifier;
...@@ -1695,10 +1704,7 @@ sub process_file($) { ...@@ -1695,10 +1704,7 @@ sub process_file($) {
$newcontents = $2; $newcontents = $2;
if ($contents ne "") { if ($contents ne "") {
$contents =~ s/\&/\\\\\\amp;/g; dump_section($section, xml_escape($contents));
$contents =~ s/\</\\\\\\lt;/g;
$contents =~ s/\>/\\\\\\gt;/g;
dump_section($section, $contents);
$section = $section_default; $section = $section_default;
} }
...@@ -1710,10 +1716,7 @@ sub process_file($) { ...@@ -1710,10 +1716,7 @@ sub process_file($) {
} elsif (/$doc_end/) { } elsif (/$doc_end/) {
if ($contents ne "") { if ($contents ne "") {
$contents =~ s/\&/\\\\\\amp;/g; dump_section($section, xml_escape($contents));
$contents =~ s/\</\\\\\\lt;/g;
$contents =~ s/\>/\\\\\\gt;/g;
dump_section($section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} }
...@@ -1727,10 +1730,7 @@ sub process_file($) { ...@@ -1727,10 +1730,7 @@ sub process_file($) {
# @parameter line to signify start of description # @parameter line to signify start of description
if ($1 eq "" && if ($1 eq "" &&
($section =~ m/^@/ || $section eq $section_context)) { ($section =~ m/^@/ || $section eq $section_context)) {
$contents =~ s/\&/\\\\\\amp;/g; dump_section($section, xml_escape($contents));
$contents =~ s/\</\\\\\\lt;/g;
$contents =~ s/\>/\\\\\\gt;/g;
dump_section($section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment