Skip to content

Commit

Permalink
Backport of r153169
Browse files Browse the repository at this point in the history
svn path=/branches/mono-2-6/mcs/; revision=153170
  • Loading branch information
grendello committed Mar 6, 2010
1 parent f600fa9 commit 991b452
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mcs/class/System.Web/System.Web/ChangeLog
@@ -1,3 +1,9 @@
2010-03-06 Marek Habersack <mhabersack@novell.com>

* HttpUtility.cs: decode entities which use hexadecimal
encoding. Fixes bug #585992. Patch from Sebastien Morin
<smsisko@gmail.com>, thanks!

2010-02-27 Marek Habersack <mhabersack@novell.com>

* HttpRuntime.cs: added internal property DomainUnloading.
Expand Down
7 changes: 7 additions & 0 deletions mcs/class/System.Web/System.Web/HttpUtility.cs
Expand Up @@ -837,6 +837,7 @@ public static string HtmlDecode (string s)
// 3 -> '#' found after '&' and getting numbers
int state = 0;
int number = 0;
bool is_hex_value = false;
bool have_trailing_digits = false;

for (int i = 0; i < len; i++) {
Expand Down Expand Up @@ -872,6 +873,7 @@ public static string HtmlDecode (string s)
entity.Length = 0;
} else {
number = 0;
is_hex_value = false;
if (c != '#') {
state = 2;
} else {
Expand Down Expand Up @@ -902,9 +904,14 @@ public static string HtmlDecode (string s)
state = 0;
entity.Length = 0;
have_trailing_digits = false;
} else if (is_hex_value && Uri.IsHexDigit(c)) {
number = number * 16 + Uri.FromHex(c);
have_trailing_digits = true;
} else if (Char.IsDigit (c)) {
number = number * 10 + ((int) c - '0');
have_trailing_digits = true;
} else if (number == 0 && (c == 'x' || c == 'X')) {
is_hex_value = true;
} else {
state = 2;
if (have_trailing_digits) {
Expand Down
9 changes: 9 additions & 0 deletions mcs/class/System.Web/Test/System.Web/HttpUtilityTest.cs
Expand Up @@ -345,6 +345,15 @@ public void Decode1 ()
Assert.AreEqual ("\xE9", HttpUtility.HtmlDecode ("&#233;"));
}

[Test (Description="Bug #585992")]
public void Decode2 ()
{
string encodedSource = "&#169; == &#xA9; == &#XA9; and &#915; == &#x393; == &#X393;";
string utf8Result = "© == © == © and Γ == Γ == Γ";

Assert.AreEqual (utf8Result, HttpUtility.HtmlDecode (encodedSource), "#A1");
}

[Test]
public void RoundTrip ()
{
Expand Down

0 comments on commit 991b452

Please sign in to comment.