Skip to content

Commit 867c2f5

Browse files
committed
genhtml: Fix anchor IDs
HTML 4.01 transitional requires [1] that anchor IDs start with a letter, and may only contain characters of a restricted set. genhtml uses numbers as IDs for line and date bin anchors, and might use IDs with unsupported characters for user name and test name anchors. Fix this by prefixing anchor IDs with a letter depending in the type of anchor, and by replacing unsupported characters in user and test names. The following anchro prefixes are introduced: - L for line anchors - B for date bin anchors - N for owner bin anchors - T for test name anchors [1] https://www.w3.org/TR/html401/types.html#type-name Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 0d8d2ad commit 867c2f5

9 files changed

+140
-126
lines changed

bin/genhtml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ sub parse_dir_prefix(@);
270270

271271
# HTML related prototypes
272272
sub escape_html($);
273+
sub escape_id($);
273274
sub get_bar_graph_code($$$);
274275

275276
sub write_png_files();
@@ -7635,6 +7636,16 @@ END_OF_HTML
76357636
END_OF_HTML
76367637
}
76377638

7639+
sub escape_id($)
7640+
{
7641+
my ($name) = @_;
7642+
7643+
# Name/ID attribute requirements according to HTML 4.01 Transitional
7644+
$name =~ s/[^A-Za-z0-9-_:.]/_/g;
7645+
7646+
return $name;
7647+
}
7648+
76387649
# write_file_table_entry(handle, base_dir,
76397650
# [ name, [filename, fileDetails, fileHref, cbdata],
76407651
# activeTlaCols,
@@ -7702,10 +7713,10 @@ sub write_file_table_entry(*$$@)
77027713
# visible (you have to scroll up to see it).
77037714
# the fix is to put the anchor in the next column
77047715
if ($primary_key eq 'owner') {
7705-
$anchor = "<a id=$name>NAME</a>";
7716+
$anchor = '<a id="N' . escape_id($name) . '">NAME</a>';
77067717
} elsif ($primary_key eq 'date') {
77077718
my $bin = $SummaryInfo::ageHeaderToBin{$name};
7708-
$anchor = "<a id=$bin>NAME</a>";
7719+
$anchor = "<a id=\"B$bin\">NAME</a>";
77097720
}
77107721
}
77117722

@@ -7714,10 +7725,10 @@ sub write_file_table_entry(*$$@)
77147725
if ($main::frames) {
77157726
# href to anchor in frame doesn't seem to work in either firefox
77167727
# or chrome. However, this seems like the right syntax.
7717-
$tableHref .= "href=\"$file_link#__LINE__\" target=\"source\""
7728+
$tableHref .= "href=\"$file_link#L__LINE__\" target=\"source\""
77187729
if 0;
77197730
} else {
7720-
$tableHref = "href=\"$file_link#__LINE__\"";
7731+
$tableHref = "href=\"$file_link#L__LINE__\"";
77217732
}
77227733
}
77237734
# First column: name
@@ -7759,12 +7770,12 @@ sub write_file_table_entry(*$$@)
77597770
if ($page_type eq 'owner') {
77607771
$bin = $esc_name
77617772
if ($primary_key eq 'name');
7762-
$namecode .= "-bin_owner." . $html_ext . "#" . $bin;
7773+
$namecode .= "-bin_owner." . $html_ext . "#N" . escape_id($bin);
77637774
$help = "owner $bin";
77647775
} elsif ($page_type eq 'date') {
77657776
$bin = $SummaryInfo::ageHeaderToBin{$name}
77667777
if ($primary_key eq 'name');
7767-
$namecode .= "-bin_date." . $html_ext . "#$bin";
7778+
$namecode .= "-bin_date." . $html_ext . "#B$bin";
77687779
$help =
77697780
"the period '" . $SummaryInfo::ageGroupHeader[$bin] . "'";
77707781
} else {
@@ -8029,9 +8040,10 @@ END_OF_HTML
80298040
sub write_test_table_entry(*$$)
80308041
{
80318042
# *************************************************************
8043+
my $name = escape_id($_[1]);
80328044

80338045
write_html($_[0], <<END_OF_HTML);
8034-
<dt>$_[1]<a id="$_[1]">&nbsp;</a></dt>
8046+
<dt>$_[1]<a id="T$name">&nbsp;</a></dt>
80358047
<dd>$_[2]<br><br></dd>
80368048
END_OF_HTML
80378049

@@ -8330,7 +8342,8 @@ sub get_branch_html($$)
83308342
my $line = $differentialBranch->line();
83318343
my $next = $fileDetail->nextBranchTlaGroup($tla, $line);
83328344
$class .= " tlaBg$tla";
8333-
$href = "<a href=\"#" . (defined($next) ? $next : 'top') .
8345+
$href =
8346+
"<a href=\"#" . (defined($next) ? "L$next" : 'top') .
83348347
"\" title=\"TITLE\">$char</a>";
83358348
$tlaLinks{$tla} = $href;
83368349
}
@@ -8438,7 +8451,7 @@ sub write_source_line(*$$$$)
84388451
my $next = $cbdata->sourceDetail()->nextTlaGroup($bucket, $line);
84398452
$tlaIsHref = 1;
84408453
# if no next segment in this category - then go to top to page.
8441-
$next = 'top' if (!defined($next));
8454+
$next = defined($next) ? "L$next" : "top";
84428455
my $anchorClass = "";
84438456
if ($tla ne 'UNK') {
84448457
$class .= " tlaBg$bucket";
@@ -8489,7 +8502,7 @@ sub write_source_line(*$$$$)
84898502

84908503
# Write out a line number navigation anchor every $nav_resolution
84918504
# lines if necessary
8492-
$anchor_start = "<a id=\"$line\">";
8505+
$anchor_start = "<a id=\"L$line\">";
84938506
$anchor_end = "</a>";
84948507

84958508
# *************************************************************
@@ -8617,7 +8630,7 @@ sub write_source_line(*$$$$)
86178630
->nextInDateBin($newBin, $bucket, $line);
86188631
$cbdata->nextDate($newBin, $bucket, $next);
86198632

8620-
$next = "top" if (!defined($next));
8633+
$next = defined($next) ? "L$next" : "top";
86218634
my $dateBin = $SummaryInfo::ageGroupHeader[$newBin];
86228635
my $label =
86238636
$main::use_legacyLabels ?
@@ -8636,7 +8649,7 @@ sub write_source_line(*$$$$)
86368649
my $next = $cbdata->sourceDetail()
86378650
->nextInOwnerBin($src_owner, $bucket, $line);
86388651
$cbdata->nextOwner($src_owner, $bucket, $next);
8639-
$next = "top" if (!defined($next));
8652+
$next = defined($next) ? "L$next" : "top";
86408653
my $label =
86418654
$main::use_legacyLabels ?
86428655
$SummaryInfo::tlaToLegacySrcLabel{$bucket} :
@@ -8817,7 +8830,7 @@ sub write_overview_line(*$$$)
88178830
# *************************************************************
88188831

88198832
write_html($_[0], <<END_OF_HTML);
8820-
<area shape="rect" coords="0,$y1,$x2,$y2" href="$_[1].gcov.$html_ext#$_[3]" target="source" alt="overview">
8833+
<area shape="rect" coords="0,$y1,$x2,$y2" href="$_[1].gcov.$html_ext#L$_[3]" target="source" alt="overview">
88218834
END_OF_HTML
88228835

88238836
# *************************************************************
@@ -8941,7 +8954,7 @@ sub buildDateSummaryTable($$$$$$$$$)
89418954
my $href = $SummaryInfo::ageGroupHeader[$bin];
89428955
if (defined($detailLink)) {
89438956
$href =
8944-
"<a href=\"$page#$bin\" title=\"click to go to coverage summary for the period '$href'\">$href</a>";
8957+
"<a href=\"$page#B$bin\" title=\"click to go to coverage summary for the period '$href'\">$href</a>";
89458958
}
89468959
$hit -= $found # negative number
89478960
if ($main::opt_missed);
@@ -8988,7 +9001,7 @@ sub buildDateSummaryTable($$$$$$$$$)
89889001
if ($covType ne 'line');
89899002
$popup .= "in &ldquo;$dateBin&rdquo; bin\"";
89909003
$value =
8991-
"<a href=\"#$firstAppearance\"$popup$color>$value</a>";
9004+
"<a href=\"#L$firstAppearance\"$popup$color>$value</a>";
89929005
}
89939006
push(@dataRow, [undef, $class, $value]);
89949007
}
@@ -9065,7 +9078,8 @@ sub buildOwnerSummaryTable($$$$$$$$$)
90659078
my $href = $esc_name;
90669079
if (defined($detailLink)) {
90679080
$href =
9068-
"<a href=\"$page#$name\" title=\"click to go to coverage summary for owner '$esc_name'\">$esc_name</a>";
9081+
"<a href=\"$page#N" . escape_id($name) .
9082+
"\" title=\"click to go to coverage summary for owner '$esc_name'\">$esc_name</a>";
90699083
}
90709084
$hit -= $found # negative number
90719085
if ($main::opt_missed);
@@ -9108,7 +9122,7 @@ sub buildOwnerSummaryTable($$$$$$$$$)
91089122
if ($covType ne 'line');
91099123
$popup .= "in &ldquo;$name&rdquo; bin\"";
91109124
$value =
9111-
"<a href=\"#$firstAppearance\"$popup$color>$value</a>";
9125+
"<a href=\"#L$firstAppearance\"$popup$color>$value</a>";
91129126
}
91139127
push(@dataRow, [undef, $class, $value]);
91149128
}
@@ -9147,7 +9161,7 @@ sub buildHeaderSummaryTableRow
91479161
$main::use_legacyLabels ? $SummaryInfo::tlaToLegacy{$tla} :
91489162
$tla;
91499163
$popup .= "$label\"";
9150-
$value = "<a href=\"#$firstAppearance\"$popup>$value</a>";
9164+
$value = "<a href=\"#L$firstAppearance\"$popup>$value</a>";
91519165
}
91529166
push(@row, [undef, "headerCovTableEntry", $value]);
91539167
}
@@ -10327,8 +10341,8 @@ sub write_file_table(*$$$$$)
1032710341
my $href = $testname;
1032810342
# Insert link to description of available
1032910343
if ($test_description{$testname}) {
10330-
$href = "<a href=\"$base_dir" .
10331-
"descriptions.$html_ext#$testname\">" . "$testname</a>";
10344+
$href = "<a href=\"$base_dir" . "descriptions.$html_ext#T" .
10345+
escape_id($testname) . "\">" . "$testname</a>";
1033210346
}
1033310347
write_file_table_detail_entry(*HTML_HANDLE, $base_dir,
1033410348
$href, $showBinDetail, $activeTlaCols, @results);
@@ -10627,7 +10641,7 @@ END_OF_HTML
1062710641

1062810642
write_html(*HTML_HANDLE, <<END_OF_HTML);
1062910643
<tr>
10630-
<td class="coverFn"><a href="$source#$startline">$name</a></td>
10644+
<td class="coverFn"><a href="$source#L$startline">$name</a></td>
1063110645
$tlaRow
1063210646
<td class="$countstyle">$count</td>
1063310647
$lineProportionRow
@@ -10673,7 +10687,7 @@ END_OF_HTML
1067310687
}
1067410688
write_html(*HTML_HANDLE, <<END_OF_HTML);
1067510689
<tr>
10676-
<td class="coverFnAlias"><a href="$source#$startline">$alias</a></td>
10690+
<td class="coverFnAlias"><a href="$source#L$startline">$alias</a></td>
1067710691
$tlaRow
1067810692
<td class="$style">$hit</td>
1067910693
$lineProportionRow
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<td class="coverFn"><a href="test.cpp.gcov.html#19">added()</a></td>
1+
<td class="coverFn"><a href="test.cpp.gcov.html#L19">added()</a></td>
22
<td class="tlaCBC">CBC</td>
33
--
4-
<td class="coverFn"><a href="test.cpp.gcov.html#26">added_notCalled()</a></td>
4+
<td class="coverFn"><a href="test.cpp.gcov.html#L26">added_notCalled()</a></td>
55
<td class="tlaUBC">UBC</td>
66
--
7-
<td class="coverFn"><a href="test.cpp.gcov.html#63">excluded()</a></td>
7+
<td class="coverFn"><a href="test.cpp.gcov.html#L63">excluded()</a></td>
88
<td class="tlaCBC">CBC</td>
99
--
10-
<td class="coverFn"><a href="test.cpp.gcov.html#72">excluded_notCalled()</a></td>
10+
<td class="coverFn"><a href="test.cpp.gcov.html#L72">excluded_notCalled()</a></td>
1111
<td class="tlaUBC">UBC</td>
1212
--
13-
<td class="coverFn"><a href="test.cpp.gcov.html#45">included()</a></td>
13+
<td class="coverFn"><a href="test.cpp.gcov.html#L45">included()</a></td>
1414
<td class="tlaCBC">CBC</td>
1515
--
16-
<td class="coverFn"><a href="test.cpp.gcov.html#54">included_notCalled()</a></td>
16+
<td class="coverFn"><a href="test.cpp.gcov.html#L54">included_notCalled()</a></td>
1717
<td class="tlaUBC">UBC</td>
1818
--
19-
<td class="coverFn"><a href="test.cpp.gcov.html#80">inserted()</a></td>
19+
<td class="coverFn"><a href="test.cpp.gcov.html#L80">inserted()</a></td>
2020
<td class="tlaGNC">GNC</td>
2121
--
22-
<td class="coverFn"><a href="test.cpp.gcov.html#85">inserted_notCalled()</a></td>
22+
<td class="coverFn"><a href="test.cpp.gcov.html#L85">inserted_notCalled()</a></td>
2323
<td class="tlaUNC">UNC</td>
2424
--
25-
<td class="coverFn"><a href="test.cpp.gcov.html#90">main</a></td>
25+
<td class="coverFn"><a href="test.cpp.gcov.html#L90">main</a></td>
2626
<td class="tlaCBC">CBC</td>
2727
--
28-
<td class="coverFn"><a href="test.cpp.gcov.html#33">removed()</a></td>
28+
<td class="coverFn"><a href="test.cpp.gcov.html#L33">removed()</a></td>
2929
<td class="tlaCBC">CBC</td>
3030
--
31-
<td class="coverFn"><a href="test.cpp.gcov.html#39">removed_notCalled()</a></td>
31+
<td class="coverFn"><a href="test.cpp.gcov.html#L39">removed_notCalled()</a></td>
3232
<td class="tlaUBC">UBC</td>
3333
--
34-
<td class="coverFn"><a href="test.cpp.gcov.html#7">unchanged()</a></td>
34+
<td class="coverFn"><a href="test.cpp.gcov.html#L7">unchanged()</a></td>
3535
<td class="tlaCBC">CBC</td>
3636
--
37-
<td class="coverFn"><a href="test.cpp.gcov.html#13">unchanged_notCalled()</a></td>
37+
<td class="coverFn"><a href="test.cpp.gcov.html#L13">unchanged_notCalled()</a></td>
3838
<td class="tlaUBC">UBC</td>
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<td class="coverFn"><a href="test.cpp.gcov.html#19">added()</a></td>
1+
<td class="coverFn"><a href="test.cpp.gcov.html#L19">added()</a></td>
22
<td class="tlaGNC">GNC</td>
33
--
4-
<td class="coverFn"><a href="test.cpp.gcov.html#26">added_notCalled()</a></td>
4+
<td class="coverFn"><a href="test.cpp.gcov.html#L26">added_notCalled()</a></td>
55
<td class="tlaUNC">UNC</td>
66
--
7-
<td class="coverFn"><a href="test.cpp.gcov.html#63">excluded()</a></td>
7+
<td class="coverFn"><a href="test.cpp.gcov.html#L63">excluded()</a></td>
88
<td class="tlaGNC">GNC</td>
99
--
10-
<td class="coverFn"><a href="test.cpp.gcov.html#72">excluded_notCalled()</a></td>
10+
<td class="coverFn"><a href="test.cpp.gcov.html#L72">excluded_notCalled()</a></td>
1111
<td class="tlaUNC">UNC</td>
1212
--
13-
<td class="coverFn"><a href="test.cpp.gcov.html#45">included()</a></td>
13+
<td class="coverFn"><a href="test.cpp.gcov.html#L45">included()</a></td>
1414
<td class="tlaGNC">GNC</td>
1515
--
16-
<td class="coverFn"><a href="test.cpp.gcov.html#54">included_notCalled()</a></td>
16+
<td class="coverFn"><a href="test.cpp.gcov.html#L54">included_notCalled()</a></td>
1717
<td class="tlaUNC">UNC</td>
1818
--
19-
<td class="coverFn"><a href="test.cpp.gcov.html#80">inserted()</a></td>
19+
<td class="coverFn"><a href="test.cpp.gcov.html#L80">inserted()</a></td>
2020
<td class="tlaGNC">GNC</td>
2121
--
22-
<td class="coverFn"><a href="test.cpp.gcov.html#85">inserted_notCalled()</a></td>
22+
<td class="coverFn"><a href="test.cpp.gcov.html#L85">inserted_notCalled()</a></td>
2323
<td class="tlaUNC">UNC</td>
2424
--
25-
<td class="coverFn"><a href="test.cpp.gcov.html#90">main</a></td>
25+
<td class="coverFn"><a href="test.cpp.gcov.html#L90">main</a></td>
2626
<td class="tlaGNC">GNC</td>
2727
--
28-
<td class="coverFn"><a href="test.cpp.gcov.html#33">removed()</a></td>
28+
<td class="coverFn"><a href="test.cpp.gcov.html#L33">removed()</a></td>
2929
<td class="tlaGNC">GNC</td>
3030
--
31-
<td class="coverFn"><a href="test.cpp.gcov.html#39">removed_notCalled()</a></td>
31+
<td class="coverFn"><a href="test.cpp.gcov.html#L39">removed_notCalled()</a></td>
3232
<td class="tlaUNC">UNC</td>
3333
--
34-
<td class="coverFn"><a href="test.cpp.gcov.html#7">unchanged()</a></td>
34+
<td class="coverFn"><a href="test.cpp.gcov.html#L7">unchanged()</a></td>
3535
<td class="tlaCBC">CBC</td>
3636
--
37-
<td class="coverFn"><a href="test.cpp.gcov.html#13">unchanged_notCalled()</a></td>
37+
<td class="coverFn"><a href="test.cpp.gcov.html#L13">unchanged_notCalled()</a></td>
3838
<td class="tlaUBC">UBC</td>
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<td class="coverFn"><a href="test.cpp.gcov.html#19">added()</a></td>
1+
<td class="coverFn"><a href="test.cpp.gcov.html#L19">added()</a></td>
22
<td class="tlaLBC">LBC</td>
33
--
4-
<td class="coverFn"><a href="test.cpp.gcov.html#26">added_notCalled()</a></td>
4+
<td class="coverFn"><a href="test.cpp.gcov.html#L26">added_notCalled()</a></td>
55
<td class="tlaUBC">UBC</td>
66
--
7-
<td class="coverFn"><a href="test.cpp.gcov.html#63">excluded()</a></td>
7+
<td class="coverFn"><a href="test.cpp.gcov.html#L63">excluded()</a></td>
88
<td class="tlaLBC">LBC</td>
99
--
10-
<td class="coverFn"><a href="test.cpp.gcov.html#72">excluded_notCalled()</a></td>
10+
<td class="coverFn"><a href="test.cpp.gcov.html#L72">excluded_notCalled()</a></td>
1111
<td class="tlaUBC">UBC</td>
1212
--
13-
<td class="coverFn"><a href="test.cpp.gcov.html#45">included()</a></td>
13+
<td class="coverFn"><a href="test.cpp.gcov.html#L45">included()</a></td>
1414
<td class="tlaLBC">LBC</td>
1515
--
16-
<td class="coverFn"><a href="test.cpp.gcov.html#54">included_notCalled()</a></td>
16+
<td class="coverFn"><a href="test.cpp.gcov.html#L54">included_notCalled()</a></td>
1717
<td class="tlaUBC">UBC</td>
1818
--
19-
<td class="coverFn"><a href="test.cpp.gcov.html#80">inserted()</a></td>
19+
<td class="coverFn"><a href="test.cpp.gcov.html#L80">inserted()</a></td>
2020
<td class="tlaUNC">UNC</td>
2121
--
22-
<td class="coverFn"><a href="test.cpp.gcov.html#85">inserted_notCalled()</a></td>
22+
<td class="coverFn"><a href="test.cpp.gcov.html#L85">inserted_notCalled()</a></td>
2323
<td class="tlaUNC">UNC</td>
2424
--
25-
<td class="coverFn"><a href="test.cpp.gcov.html#90">main</a></td>
25+
<td class="coverFn"><a href="test.cpp.gcov.html#L90">main</a></td>
2626
<td class="tlaCBC">CBC</td>
2727
--
28-
<td class="coverFn"><a href="test.cpp.gcov.html#33">removed()</a></td>
28+
<td class="coverFn"><a href="test.cpp.gcov.html#L33">removed()</a></td>
2929
<td class="tlaLBC">LBC</td>
3030
--
31-
<td class="coverFn"><a href="test.cpp.gcov.html#39">removed_notCalled()</a></td>
31+
<td class="coverFn"><a href="test.cpp.gcov.html#L39">removed_notCalled()</a></td>
3232
<td class="tlaUBC">UBC</td>
3333
--
34-
<td class="coverFn"><a href="test.cpp.gcov.html#7">unchanged()</a></td>
34+
<td class="coverFn"><a href="test.cpp.gcov.html#L7">unchanged()</a></td>
3535
<td class="tlaLBC">LBC</td>
3636
--
37-
<td class="coverFn"><a href="test.cpp.gcov.html#13">unchanged_notCalled()</a></td>
37+
<td class="coverFn"><a href="test.cpp.gcov.html#L13">unchanged_notCalled()</a></td>
3838
<td class="tlaUBC">UBC</td>

0 commit comments

Comments
 (0)