In a program I'm using a rather sophisticated parameter for CGI's start_html
, but that results in a duplicate rel
attribute for the CSS passed via -style
.
Example code:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $attr = {
'-script' => [
{
'-src' => '.js',
'-type' => 'text/javascript'
},
{
'-src' => '.js',
'-type' => 'text/javascript'
},
{
'-type' => 'text/javascript',
'-src' => '.js'
}
],
'-noscript' => '<link type="text/css" href=".css" id="3.css" title="No Script Additions" rel="stylesheet" />',
'-encoding' => 'utf-8',
'-author' => 'Me <[email protected]>',
'-lang' => 'de-DE',
'-style' => [
{
'-id' => '2.css',
'-type' => 'text/css',
'-src' => '.css',
'-rel' => 'stylesheet alternate',
'-title' => 'JavaScript Additions'
}
],
'-meta' => {
'copyright' => 'Copyright ...',
'keywords' => 'bla',
'description' => 'Application to ...'
},
'-title' => '[ldapdir-3.8] Login'
};
my $query = CGI->new;
print $query->start_html($attr), "\n";
Output:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
".dtd">
<html xmlns="; lang="de-DE" xml:lang="de-DE">
<head>
<title>[ldapdir-3.8] Login</title>
<link rev="made" href="mailto:Me%20%26lt%3Bmy%40e.mail%26gt%3B" />
<meta name="copyright" content="Copyright ..." />
<meta name="description" content="Application to ..." />
<meta name="keywords" content="bla" />
<link rel="stylesheet" type="text/css" href=".css" id="2.css" rel="stylesheet alternate" title="JavaScript Additions"/>
<script src=".js" type="text/javascript"></script>
<script src=".js" type="text/javascript"></script>
<script src=".js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<noscript>
<link type="text/css" href=".css" id="3.css" title="No Script Additions" rel="stylesheet" />
</noscript>
</head>
<body>
I tend to believe it's a bug in $CGI::VERSION='3.63'
.
How can I fix it?
In a program I'm using a rather sophisticated parameter for CGI's start_html
, but that results in a duplicate rel
attribute for the CSS passed via -style
.
Example code:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $attr = {
'-script' => [
{
'-src' => 'https://server.domain./app/js/0.js',
'-type' => 'text/javascript'
},
{
'-src' => 'https://server.domain./app/js/2.js',
'-type' => 'text/javascript'
},
{
'-type' => 'text/javascript',
'-src' => 'https://server.domain./app/js/3.js'
}
],
'-noscript' => '<link type="text/css" href="https://server.domain./app/style/3.css" id="3.css" title="No Script Additions" rel="stylesheet" />',
'-encoding' => 'utf-8',
'-author' => 'Me <[email protected]>',
'-lang' => 'de-DE',
'-style' => [
{
'-id' => '2.css',
'-type' => 'text/css',
'-src' => 'https://server.domain./app/style/2.css',
'-rel' => 'stylesheet alternate',
'-title' => 'JavaScript Additions'
}
],
'-meta' => {
'copyright' => 'Copyright ...',
'keywords' => 'bla',
'description' => 'Application to ...'
},
'-title' => '[ldapdir-3.8] Login'
};
my $query = CGI->new;
print $query->start_html($attr), "\n";
Output:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3./1999/xhtml" lang="de-DE" xml:lang="de-DE">
<head>
<title>[ldapdir-3.8] Login</title>
<link rev="made" href="mailto:Me%20%26lt%3Bmy%40e.mail%26gt%3B" />
<meta name="copyright" content="Copyright ..." />
<meta name="description" content="Application to ..." />
<meta name="keywords" content="bla" />
<link rel="stylesheet" type="text/css" href="https://server.domain./app/style/2.css" id="2.css" rel="stylesheet alternate" title="JavaScript Additions"/>
<script src="https://server.domain./app/js/0.js" type="text/javascript"></script>
<script src="https://server.domain./app/js/2.js" type="text/javascript"></script>
<script src="https://server.domain./app/js/3.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<noscript>
<link type="text/css" href="https://server.domain./app/style/3.css" id="3.css" title="No Script Additions" rel="stylesheet" />
</noscript>
</head>
<body>
I tend to believe it's a bug in $CGI::VERSION='3.63'
.
How can I fix it?
1 Answer
Reset to default 3After reading LIMITED SUPPORT FOR CASCADING STYLE SHEETS I changed the attributes like this (so I dropped -rel
and -type
while adding '-alternate' => 1
):
# ...
'-style' => [
{
'-id' => '2.css',
'-alternate' => 1,
'-src' => 'https://server.domain./app/style/2.css',
'-title' => 'JavaScript Additions'
}
],
# ...
and the resulting HTML was
<!-- ... -->
<link rel="alternate stylesheet" type="text/css" href="https://server.domain./app/style/2.css" title="JavaScript Additions" id="2.css"/>
<!-- ... -->
and the duplicate rel
was gone.
-style
on top level of the%attr
array you already defined the "stylesheet". You do not need to define-rel
manually. – White Owl Commented Nov 19, 2024 at 13:32-link
instead of-style
? – ikegami Commented Nov 19, 2024 at 15:09-style
is just an alias for-link
having pre-set'-rel' => 'stylesheet'
? – U. Windl Commented Nov 20, 2024 at 6:03