UrlEncode() Bug?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have noticed that System.Web.HttpUtility.UrlEncode() encodes spaces as plus
signs (+) rather than the hex encoded "%20". Why?

In most cases, this is not a problem, but it breaks fragments. For example,
if you created the following on a page <a name="example fragment">example</a>:

"http://www.example.com/index.htm#example+fragment" will not jump down to
the proper area of the page
"http://www.example.com/index.htm#example fragment" works as expected
(I have tested this in IE6 and Firefox 1.0.1 on WinXP)

While using a plus sign when creating your own URLs is valid, the proper way
to replace a space in a URL is to use "%20", so this seems to be a .NET bug.
 
not a bug, but historial. the original url standard required spaces to
replaced with "+"s. hex coding was added later, so spaces can also be hex
coded.

note: spaces are not really valid for an element name (nor actually is MS
use of a leading "_"). names are supposed to start with a letter and only
contain alphanumerics plus the "_".

-- bruce (sqlwork.com)


| I have noticed that System.Web.HttpUtility.UrlEncode() encodes spaces as
plus
| signs (+) rather than the hex encoded "%20". Why?
|
| In most cases, this is not a problem, but it breaks fragments. For
example,
| if you created the following on a page <a name="example
fragment">example</a>:
|
| "http://www.example.com/index.htm#example+fragment" will not jump down to
| the proper area of the page
| "http://www.example.com/index.htm#example fragment" works as expected
| (I have tested this in IE6 and Firefox 1.0.1 on WinXP)
|
| While using a plus sign when creating your own URLs is valid, the proper
way
| to replace a space in a URL is to use "%20", so this seems to be a .NET
bug.
 
note: spaces are not really valid for an element

This is not true. The name attribute of the anchor (a)
element is CDATA, which allows spaces. Because of this,
I still contend that identifies a bug with UrlEncode().
not a bug, but historial. the original url
standard required spaces to replaced with "+"s.
hex coding was added later, so spaces can also
be hex coded.

Historical? Original? What about new and improved? My
original example shows that using "+" has its flaws. Hex
encoding doesn't cause these problems, so should be used
instead.

How do you send bug reports and RFEs to Microsoft?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top