Click here to get back home

ampersand in urls when using xhtml 1.0 strict

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
ampersand in urls when using xhtml 1.0 strict mark4asp 12-17-2007
Posted by Michael Fesser on December 17, 2007, 9:29 am
Please log in for more thread options
.oO(mark4asp)

>The immediate problem is now fixed. Somehow the page with the urls was
>missing a Content-Type header:
>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Surely not. If this "fixed" your problem, then there's something wrong
with your server.

>After including this header I was able to remove the encoded
>ampersands, [ &amp; ], to replace them with just a &. The xhtml
>syntax checker no longer indicated errors here and the page navigation
>now works.

I doubt that. Ampersands in a URL _must_ be encoded.

Micha

Posted by Harlan Messinger on December 17, 2007, 9:35 am
Please log in for more thread options
mark4asp wrote:
> mark4asp wrote:
>
>> When I write a url in xhtml, with an unencoded ampersand, like this:
>>
>> http://localhost:2063/Client/ViewReport.aspx?Ref=58&Type=SUMMARY
>>
>> the xhtml sytax checker correctly indicates an error, telling me that
>> it should be:
>>
>> http://localhost:2063/Client/ViewReport.aspx?Ref=58&amp;Type=SUMMARY
>>
>> see: <http://www.htmlhelp.com/tools/validator/problems.html#amp>
>>
>> However the last sentence there ends:
>>
>>         "the browser translates "&amp;" to "&" so the Web server would only
>> see "&" and not "&amp;" in the query string of the request."
>>
>> My web server is clearly seeing &amp; and the browser (FF 1.0.0.11) is
>> also showing &amp; in the url.
>>
>> I am using:
>>         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>>
>> with no xml prefix because, as we all know, IE6 breaks when the xml
>> prefix is present.
>>
>> What is the cause and solution of this problem.
>>
>> I am using FF 1.0.0.11, via a local asp.net 2.0 site through the mini
>> webserver (Cassini) on WinXP SP2 with all latest o/s updates installed
>> (apart from IE7, I am using IE6 on this PC).
>>
>> Do I have to apply a url decode algorithm when the web page loads?
>> That is far from ideal because the problem here is that the browser is
>> not showing the decoded url.
>>
>> Is this a bug in FF?
>>
>> Finally is there a DOCTYPE I can use to force all the 5 major
>> browsers: IE6, IE7, FF, Opera, Safari to all render in strict mode
>> when displaying xhtml?
>
> The immediate problem is now fixed. Somehow the page with the urls was
> missing a Content-Type header:
>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>
> After including this header I was able to remove the encoded
> ampersands, [ &amp; ], to replace them with just a &. The xhtml
> syntax checker no longer indicated errors here and the page navigation
> now works.

First, this is very strange because if your browser was displaying the
page as HTML, then it was already receiving a content type header from
the web server (which the web server should always send--the META tag
should only be useful for cases where the server isn't sending a content
type header or when you are opening up a static web page directly on
your system instead of requesting it from a web browser) telling it that
the page was HTML, or else there was no header and the browser was
treating it as HTML by default.

Second, this is very strange because NOT encoding ampersands *is*
invalid and the W3C validator wouldn't start treating it as valid
because you included a META tag that wasn't necessary anyway and that
wouldn't cause the effect that you've stated.

Posted by mark4asp on December 17, 2007, 12:23 pm
Please log in for more thread options
Harlan Messinger wrote:

> mark4asp wrote:
> > mark4asp wrote:
> >
> > > When I write a url in xhtml, with an unencoded ampersand, like
> > > this:
> > >
> > > http://localhost:2063/Client/ViewReport.aspx?Ref=58&Type=SUMMARY
> > >
> > > the xhtml sytax checker correctly indicates an error, telling me
> > > that it should be:
> > >
> > > http://localhost:2063/Client/ViewReport.aspx?Ref=58&amp;Type=SUMMA
> > > RY
> > >
> > > see: <http://www.htmlhelp.com/tools/validator/problems.html#amp>
> > >
> > > However the last sentence there ends:
> > >
> > >         "the browser translates "&amp;" to "&" so the Web server would
> > > only see "&" and not "&amp;" in the query string of the request."
> > >
> > > My web server is clearly seeing &amp; and the browser (FF
> > > 1.0.0.11) is also showing &amp; in the url.
> > >
> > > I am using:
> > >         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> > >
> > > with no xml prefix because, as we all know, IE6 breaks when the
> > > xml prefix is present.
> > >
> > > What is the cause and solution of this problem.
> > >
> > > I am using FF 1.0.0.11, via a local asp.net 2.0 site through the
> > > mini webserver (Cassini) on WinXP SP2 with all latest o/s updates
> > > installed (apart from IE7, I am using IE6 on this PC).
> > >
> > > Do I have to apply a url decode algorithm when the web page loads?
> > > That is far from ideal because the problem here is that the
> > > browser is not showing the decoded url.
> > >
> > > Is this a bug in FF?
> > >
> > > Finally is there a DOCTYPE I can use to force all the 5 major
> > > browsers: IE6, IE7, FF, Opera, Safari to all render in strict
> > > mode when displaying xhtml?
> >
> > The immediate problem is now fixed. Somehow the page with the urls
> > was missing a Content-Type header:
> >         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
> > />
> >
> > After including this header I was able to remove the encoded
> > ampersands, [ &amp; ], to replace them with just a &. The xhtml
> > syntax checker no longer indicated errors here and the page
> > navigation now works.
>
> First, this is very strange because if your browser was displaying
> the page as HTML, then it was already receiving a content type header
> from the web server (which the web server should always send--the
> META tag should only be useful for cases where the server isn't
> sending a content type header or when you are opening up a static web
> page directly on your system instead of requesting it from a web
> browser) telling it that the page was HTML, or else there was no
> header and the browser was treating it as HTML by default.
>
> Second, this is very strange because NOT encoding ampersands is
> invalid and the W3C validator wouldn't start treating it as valid
> because you included a META tag that wasn't necessary anyway and that
> wouldn't cause the effect that you've stated.

OK. I didn't check validity using the W3C. I used an Add-on available
for Firefox [HTML validator 0.8.4.0]. I have just now discovered the
Total Validator Add-on, so I will install that too and check again.

But in any case, if my urls have an &amp; why is FF giving the &amp; to
the server [Is it a bug?]. It clearly states in the W3C documentation
that the &amp; is to be converted by the browser so that an & shows in
the address bar


Posted by André Gillibert on December 18, 2007, 6:02 pm
Please log in for more thread options
mark4asp wrote:

> But in any case, if my urls have an &amp; why is FF giving the &amp; to
> the server [Is it a bug?].

It may be, or your server software stupidly encodes URI on input or
output...
I find it hard to believe that you didn't test on any other browser than
this outdated, most probably bug-ridden, Firefox.
Cannot you test with at least ONE other browser: FF 1.5, Mozilla, IE,
Opera, lynx or whatever browser you can get.

> It clearly states in the W3C documentation
> that the &amp; is to be converted by the browser so that an & shows in
> the address bar

True.


--
If you've a question that doesn't belong to Usenet, contact me at
<tabkanDELETETHISnaz at yahoDELETETHATo.fr>

Posted by mark4asp on December 20, 2007, 9:34 am
Please log in for more thread options
mark4asp wrote:

> When I write a url in xhtml, with an unencoded ampersand, like this:
>
> http://localhost:2063/Client/ViewReport.aspx?Ref=58&Type=SUMMARY
>
> the xhtml sytax checker correctly indicates an error, telling me that
> it should be:
>
> http://localhost:2063/Client/ViewReport.aspx?Ref=58&amp;Type=SUMMARY
>
> see: <http://www.htmlhelp.com/tools/validator/problems.html#amp>
>
> However the last sentence there ends:
>
>         "the browser translates "&amp;" to "&" so the Web server would only
> see "&" and not "&amp;" in the query string of the request."
>
> My web server is clearly seeing &amp; and the browser (FF 1.0.0.11) is
> also showing &amp; in the url.
>
> I am using:
>         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> with no xml prefix because, as we all know, IE6 breaks when the xml
> prefix is present.
>
> What is the cause and solution of this problem.
>
> I am using FF 1.0.0.11, via a local asp.net 2.0 site through the mini
> webserver (Cassini) on WinXP SP2 with all latest o/s updates installed
> (apart from IE7, I am using IE6 on this PC).
>
> Do I have to apply a url decode algorithm when the web page loads?
> That is far from ideal because the problem here is that the browser is
> not showing the decoded url.
>
> Is this a bug in FF?
>
> Finally is there a DOCTYPE I can use to force all the 5 major
> browsers: IE6, IE7, FF, Opera, Safari to all render in strict mode
> when displaying xhtml?

Thanks to all who replied.

The problem is inconsistent rendering by the microsoft controls. The
GridView does not turn an & into a &amp; but the Repeater does.


Here is a snippet of the code as actually given to the browser.

You can see the relevant links here:

<a id="repItaly_ctl02_lnkShowMandate" title="View Report"
href="../search/ViewReport.aspx?Ref=5756&amp;amp;Type=MANDATE"><img
src="images/view2.gif" class="ImageIcon" alt="View Report" /></a>

Aiiiheeeeee. The bastards. What are they trying to do to me? The
asp.net Repeater control is adding an extra ';amp'

Here is a snippet from the GridView. Good Code.

        <td class="tdCol03"><a
href="../search/ViewReport.aspx?Ref=5852&amp;Type=MANDATE"><img
src="images/view2.gif" class="ImageIcon" alt="View Report" /></a></td>
                                
                                
Here is a snippet from the amended Repeater (now fixed):

        <td class="tc03">
                <a id="repItaly_ctl01_lnkShowMandate" title="View Report"
href="../search/ViewReport.aspx?Ref=5835&amp;Type=MANDATE"><img
src="images/view2.gif" class="ImageIcon" alt="View Report" /></a>
        </td>

But wait for it, I am sure you'll want to see my C# code-behind for
those two.


The relevant part of the GridView OnRowDataBound is

                                e.Row.Cells[4].Text = "<a href=\"../search/ViewReport.aspx?Ref=" +
e.Row.Cells[4].Text + "&amp;Type=MANDATE" + "\"><img
src=\"images/view2.gif\" class=\"ImageIcon\" alt=\"View Report\"
/></a>";

notice that I must tpye '&amp;' here [It won't turn a & into a &amp;]


The relevant part of the Repeater is:

                        return "../search/ViewReport.aspx?Ref=" + ((int)id).ToString() +
"&Type=MANDATE";

notice that there is only an '&'; The ancient Repeater control (from
asp,net 1.0) knows that a strict xhtml 1.0 page needs a '&amp;' so it
gives me one [turning my & into &amp; for the html].

The more modern GridView (asp.net 2.0) doesn't convert [if I put a &
there in place of the &amp; then that is exactly what's rendered and I
get an xhtml syntax error].

Bloody Microsoft.

I suppose I can blame myself too. I should've looked at the html source
straight away rather than thinking that just because I could see :
http://localhost:1616/Client_from_2007-11-06/search/ViewReport.aspx?Ref=
5756&Type=MANDATE

in the status bar, that's what was actually there. It wasn't. It was an
&amp;

Similar ThreadsPosted
utf-8 and xhtml 1.0 strict October 28, 2004, 7:26 am
xhtml vs html 4 strict May 21, 2005, 5:23 pm
Strict XHTML and div question July 14, 2005, 7:07 pm
XHTML 1.0 Strict and the Apostrophe February 15, 2008, 11:12 am
What to use intead of taget_new in XHTML/Strict July 19, 2004, 7:41 am
image maps + xhtml strict October 23, 2004, 9:16 pm
Valid XHTML strict messed up in IE Mac December 20, 2004, 7:13 pm
XHTML 1.0 Strict validation problem November 11, 2005, 10:30 am
HTML 4.01 strict / transitional vs. XHTML 1.0 September 18, 2005, 3:10 pm
Validation: XHTML Transitional vs. HTLM 4.01 Strict July 23, 2004, 6:10 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap