--- test/html-webhacc/cc.cgi 2007/11/05 09:33:52 1.23 +++ test/html-webhacc/cc.cgi 2008/02/10 02:05:30 1.31 @@ -52,7 +52,6 @@ $| = 0; my $input = get_input_document ($http, $dom); - my $inner_html_element = $http->get_parameter ('e'); my $char_length = 0; my %time; @@ -62,7 +61,12 @@
Request URI
<@{[htescape $input->{request_uri}]}>
Document URI
-
<@{[htescape $input->{uri}]}>
+
<@{[htescape $input->{uri}]}> +
]; # no yet push @nav, ['#document-info' => 'Information']; @@ -74,7 +78,7 @@
<@{[htescape $input->{base_uri}]}>
Internet Media Type
@{[htescape $input->{media_type}]} - @{[$input->{media_type_overridden} ? '(overridden)' : '']}
+ @{[$input->{media_type_overridden} ? '(overridden)' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '(sniffed; official type is: '.htescape ($input->{official_type}).')' : '(sniffed)']}
Character Encoding
@{[defined $input->{charset} ? ''.htescape ($input->{charset}).'' : '(none)']} @{[$input->{charset_overridden} ? '(overridden)' : '']}
@@ -85,46 +89,7 @@ ]; my $result = {conforming_min => 1, conforming_max => 1}; - print_http_header_section ($input, $result); - - my $doc; - my $el; - my $manifest; - - if ($input->{media_type} eq 'text/html') { - ($doc, $el) = print_syntax_error_html_section ($input, $result); - print_source_string_section (\($input->{s}), $input->{charset}); - } elsif ({ - 'text/xml' => 1, - 'application/atom+xml' => 1, - 'application/rss+xml' => 1, - 'application/svg+xml' => 1, - 'application/xhtml+xml' => 1, - 'application/xml' => 1, - }->{$input->{media_type}}) { - ($doc, $el) = print_syntax_error_xml_section ($input, $result); - print_source_string_section (\($input->{s}), $doc->input_encoding); - } elsif ($input->{media_type} eq 'text/cache-manifest') { -## TODO: MUST be text/cache-manifest - $manifest = print_syntax_error_manifest_section ($input, $result); - print_source_string_section (\($input->{s}), 'utf-8'); - } else { - ## TODO: Change HTTP status code?? - print_result_unknown_type_section ($input); - } - - if (defined $doc or defined $el) { - print_structure_dump_dom_section ($doc, $el); - my $elements = print_structure_error_dom_section ($doc, $el, $result); - print_table_section ($elements->{table}) if @{$elements->{table}}; - print_id_section ($elements->{id}) if keys %{$elements->{id}}; - print_term_section ($elements->{term}) if keys %{$elements->{term}}; - print_class_section ($elements->{class}) if keys %{$elements->{class}}; - } elsif (defined $manifest) { - print_structure_dump_manifest_section ($manifest); - print_structure_error_manifest_section ($manifest, $result); - } - + check_and_print ($input => $result); print_result_section ($result); } else { print STDOUT qq[]; @@ -143,7 +108,8 @@ ]; - for (qw/decode parse parse_xml parse_manifest check check_manifest/) { + for (qw/decode parse parse_html parse_xml parse_manifest + check check_manifest/) { next unless defined $time{$_}; open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; print $file $char_length, "\t", $time{$_}, "\n"; @@ -160,7 +126,7 @@ $result->{conforming_min} = 0; } elsif ($err->{level} eq 'w' or $err->{level} eq 'g') { $result->{$layer}->{warning}++; - } elsif ($err->{level} eq 'unsupported') { + } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') { $result->{$layer}->{unsupported}++; $result->{unsupported} = 1; } else { @@ -179,6 +145,51 @@ } } # add_error +sub check_and_print ($$) { + my ($input, $result) = @_; + + print_http_header_section ($input, $result); + + my $doc; + my $el; + my $manifest; + + if ($input->{media_type} eq 'text/html') { + ($doc, $el) = print_syntax_error_html_section ($input, $result); + print_source_string_section + (\($input->{s}), $input->{charset} || $doc->input_encoding); + } elsif ({ + 'text/xml' => 1, + 'application/atom+xml' => 1, + 'application/rss+xml' => 1, + 'application/svg+xml' => 1, + 'application/xhtml+xml' => 1, + 'application/xml' => 1, + }->{$input->{media_type}}) { + ($doc, $el) = print_syntax_error_xml_section ($input, $result); + print_source_string_section (\($input->{s}), $doc->input_encoding); + } elsif ($input->{media_type} eq 'text/cache-manifest') { +## TODO: MUST be text/cache-manifest + $manifest = print_syntax_error_manifest_section ($input, $result); + print_source_string_section (\($input->{s}), 'utf-8'); + } else { + ## TODO: Change HTTP status code?? + print_result_unknown_type_section ($input, $result); + } + + if (defined $doc or defined $el) { + print_structure_dump_dom_section ($doc, $el); + my $elements = print_structure_error_dom_section ($doc, $el, $result); + print_table_section ($elements->{table}) if @{$elements->{table}}; + print_id_section ($elements->{id}) if keys %{$elements->{id}}; + print_term_section ($elements->{term}) if keys %{$elements->{term}}; + print_class_section ($elements->{class}) if keys %{$elements->{class}}; + } elsif (defined $manifest) { + print_structure_dump_manifest_section ($manifest); + print_structure_error_manifest_section ($manifest, $result); + } +} # check_and_print + sub print_http_header_section ($$) { my ($input, $result) = @_; return unless defined $input->{header_status_code} or @@ -218,13 +229,7 @@ require Encode; require Whatpm::HTML; - - $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. - my $time1 = time; - my $t = Encode::decode ($input->{charset}, $input->{s}); - $time{decode} = time - $time1; - print STDOUT qq[

Parse Errors

@@ -252,16 +257,27 @@ my $doc = $dom->create_document; my $el; - $time1 = time; + my $inner_html_element = $http->get_parameter ('e'); if (defined $inner_html_element and length $inner_html_element) { + $input->{charset} ||= 'windows-1252'; ## TODO: for now. + my $time1 = time; + my $t = Encode::decode ($input->{charset}, $input->{s}); + $time{decode} = time - $time1; + $el = $doc->create_element_ns ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); + $time1 = time; Whatpm::HTML->set_inner_html ($el, $t, $onerror); + $time{parse} = time - $time1; } else { - Whatpm::HTML->parse_string ($t => $doc, $onerror); + my $time1 = time; + Whatpm::HTML->parse_byte_string + ($input->{charset}, $input->{s} => $doc, $onerror); + $time{parse_html} = time - $time1; } - $time{parse} = time - $time1; - + $doc->manakai_charset ($input->{official_charset}) + if defined $input->{official_charset}; + print STDOUT qq[
]; return ($doc, $el); @@ -301,6 +317,8 @@ my $doc = Message::DOM::XMLParserTemp->parse_byte_stream ($fh => $dom, $onerror, charset => $input->{charset}); $time{parse_xml} = time - $time1; + $doc->manakai_charset ($input->{official_charset}) + if defined $input->{official_charset}; print STDOUT qq[]; @@ -390,7 +408,7 @@ $r .= ''; @@ -411,6 +429,21 @@ } elsif ($nt == $child->DOCUMENT_NODE) { $r .= qq'
  • Document'; $r .= qq[