[Foomatic] [patch] PPD.pm: handle non-ASCII in PPDs

Tim Waugh twaugh at redhat.com
Wed Nov 24 08:40:20 PST 2004


Hi,

There is a problem in PPD.pm that needs some explaining.

Some PPD files contain non-ASCII characters, i.e. the top bit is set,
and we don't necessarily know the character encoding being used.  This
may occur in option names, for example, and ultimately may re-appear
in generated XML.

Unfortunately, this won't parse at all unless the encoding is given.

Here is a patch I made which works around this problem.  What do you
think? (My perl is rusty so forgive me if there is a more obvious
approach.)

Tim.
*/

--- foomatic-db-engine-3.0.2/lib/Foomatic/PPD.pm.bad-utf8	2002-10-11 02:16:34.000000000 +0100
+++ foomatic-db-engine-3.0.2/lib/Foomatic/PPD.pm	2004-11-23 19:32:26.000000000 +0000
@@ -300,11 +300,17 @@
 sub xml_esc {
     my ($in) = (@_);
     
-    $in =~ s!&!&!g;
-    $in =~ s!<!&lt;!g;
-    $in =~ s!>!&gt;!g;
+    @chars = split(//,$in);
+    $ascii = "";
+    foreach (@chars) {
+        if (ord ($_) > 127) { $_="?"; }
+        $ascii .= $_;
+    }
+    $ascii =~ s!&!&amp;!g;
+    $ascii =~ s!<!&lt;!g;
+    $ascii =~ s!>!&gt;!g;
 
-    return $in;
+    return $ascii;
 }
 
 sub pdq_filter {




More information about the Printing-foomatic mailing list