Author: adam-guest
Date: 2008-08-30 11:54:42 +0000 (Sat, 30 Aug 2008)
New Revision: 1598

Modified:
   trunk/debian/changelog
   trunk/scripts/bts.pl
Log:
If the BTS specifies a character set when serving an HTML file, add an
equivalent META tag to the cached file so that it is rendered correctly.
(pkgreport.cgi's output is now UTF-8).

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog      2008-08-23 14:11:52 UTC (rev 1597)
+++ trunk/debian/changelog      2008-08-30 11:54:42 UTC (rev 1598)
@@ -7,6 +7,9 @@
       Kinkhorst and Josh Triplett. (Closes: #493884)
     + Add a (largely undocumented) --toolname switch to allow tools calling
       bts to add themselves to the User-Agent header.
+    + If the BTS specifies a character set when serving an HTML file, add an
+      equivalent META tag to the cached file so that it is rendered correctly.
+      (pkgreport.cgi's output is now UTF-8).
   * checkbashisms: Flag "read without variable" and "read with options other
     than -r" separately to ensure that all uses are correctly matched. Thanks
     to Frank Lichtenheld for pointing this out via a related bug in lintian.

Modified: trunk/scripts/bts.pl
===================================================================
--- trunk/scripts/bts.pl        2008-08-23 14:11:52 UTC (rev 1597)
+++ trunk/scripts/bts.pl        2008-08-30 11:54:42 UTC (rev 1598)
@@ -2543,7 +2543,13 @@
     print "Downloading $url ... "
        if ! $quiet and $manual and $thing ne "css/bugs.css";
     IO::Handle::flush(\*STDOUT);
-    my ($ret, $msg, $livepage) = bts_mirror($url, $timestamp, $forcedownload);
+    my ($ret, $msg, $livepage, $contenttype) = bts_mirror($url, $timestamp, 
$forcedownload);
+    my $charset = $contenttype || '';
+    if ($charset =~ m/charset=(.*?)(;|\Z)/) {
+       $charset = $1;
+    } else {
+       $charset = "";
+    }
     if ($ret == MIRROR_UP_TO_DATE) {
        # we have an up-to-date version already, nothing to do
        # and $timestamp is guaranteed to be well-defined
@@ -2579,7 +2585,7 @@
        my $cachefile=cachefile($thing,$thgopts);
        open (OUT_CACHE, ">$cachefile") or die "bts: open $cachefile: $!\n";
 
-       $data = mangle_cache_file($data, $thing, $bug2filename, $timestamp);
+       $data = mangle_cache_file($data, $thing, $bug2filename, $timestamp, 
$charset ? $contenttype : '');
        print OUT_CACHE $data;
        close OUT_CACHE or die "bts: problems writing to $cachefile: $!\n";
 
@@ -2765,7 +2771,7 @@
 # Mangle downloaded file to work in the local cache, so
 # selectively modify the links
 sub mangle_cache_file {
-    my ($data, $thing, $bug2filename, $timestamp) = @_;
+    my ($data, $thing, $bug2filename, $timestamp, $ctype) = @_;
     my $fullmode = ! ref $bug2filename;
 
     # Undo unnecessary '+' encoding in URLs
@@ -2773,6 +2779,9 @@
     my $time=localtime(abs($timestamp));
     $data =~ s%(<BODY.*>)%$1<p><em>[Locally cached on $time by devscripts 
version $version]</em></p>%i;
     $data =~ s%href="/css/bugs.css"%href="bugs.css"%;
+    if ($ctype) {
+       $data =~ s%(<HEAD.*>)%$1<META HTTP-EQUIV="Content-Type" 
CONTENT="$ctype">%i;
+    }
 
     my @data;
     # We have to distinguish between release-critical pages and normal BTS
@@ -3428,7 +3437,7 @@
            # else OK
        }
 
-       return (MIRROR_DOWNLOADED, $response->status_line, $response->content);
+       return (MIRROR_DOWNLOADED, $response->status_line, $response->content, 
$response->header('Content-Type'));
     } else {
        return (MIRROR_ERROR, $response->status_line);
     }



-- 
To unsubscribe, send mail to [EMAIL PROTECTED]

Reply via email to