fix for fixing of escape sequences (patch 1213416)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34567 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-06-07 12:17:33 +00:00
parent 34af753dd3
commit 24ca04e7aa
2 changed files with 74 additions and 11 deletions

View File

@@ -150,10 +150,7 @@ bool wxURI::IsEscape(const wxChar*& uri)
{ {
// pct-encoded = "%" HEXDIG HEXDIG // pct-encoded = "%" HEXDIG HEXDIG
if(*uri == wxT('%') && IsHex(*(uri+1)) && IsHex(*(uri+2))) if(*uri == wxT('%') && IsHex(*(uri+1)) && IsHex(*(uri+2)))
{
uri += 3;
return true; return true;
}
else else
return false; return false;
} }
@@ -460,9 +457,15 @@ const wxChar* wxURI::ParseUserInfo(const wxChar* uri)
// userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
while(*uri && *uri != wxT('@') && *uri != wxT('/') && *uri != wxT('#') && *uri != wxT('?')) while(*uri && *uri != wxT('@') && *uri != wxT('/') && *uri != wxT('#') && *uri != wxT('?'))
{ {
if(IsUnreserved(*uri) || IsEscape(uri) || if(IsUnreserved(*uri) ||
IsSubDelim(*uri) || *uri == wxT(':')) IsSubDelim(*uri) || *uri == wxT(':'))
m_userinfo += *uri++; m_userinfo += *uri++;
else if (IsEscape(uri))
{
m_userinfo += *uri++;
m_userinfo += *uri++;
m_userinfo += *uri++;
}
else else
Escape(m_userinfo, *uri++); Escape(m_userinfo, *uri++);
} }
@@ -540,8 +543,14 @@ const wxChar* wxURI::ParseServer(const wxChar* uri)
// reg-name = *( unreserved / pct-encoded / sub-delims ) // reg-name = *( unreserved / pct-encoded / sub-delims )
while(*uri && *uri != wxT('/') && *uri != wxT(':') && *uri != wxT('#') && *uri != wxT('?')) while(*uri && *uri != wxT('/') && *uri != wxT(':') && *uri != wxT('#') && *uri != wxT('?'))
{ {
if(IsUnreserved(*uri) || IsEscape(uri) || IsSubDelim(*uri)) if(IsUnreserved(*uri) || IsSubDelim(*uri))
m_server += *uri++; m_server += *uri++;
else if (IsEscape(uri))
{
m_server += *uri++;
m_server += *uri++;
m_server += *uri++;
}
else else
Escape(m_server, *uri++); Escape(m_server, *uri++);
} }
@@ -610,9 +619,15 @@ const wxChar* wxURI::ParsePath(const wxChar* uri, bool bReference, bool bNormali
while(*uri && *uri != wxT('#') && *uri != wxT('?')) while(*uri && *uri != wxT('#') && *uri != wxT('?'))
{ {
if( IsUnreserved(*uri) || IsSubDelim(*uri) || IsEscape(uri) || if( IsUnreserved(*uri) || IsSubDelim(*uri) ||
*uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/')) *uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/'))
m_path += *uri++; m_path += *uri++;
else if (IsEscape(uri))
{
m_path += *uri++;
m_path += *uri++;
m_path += *uri++;
}
else else
Escape(m_path, *uri++); Escape(m_path, *uri++);
} }
@@ -636,9 +651,15 @@ const wxChar* wxURI::ParsePath(const wxChar* uri, bool bReference, bool bNormali
//no colon allowed //no colon allowed
while(*uri && *uri != wxT('#') && *uri != wxT('?')) while(*uri && *uri != wxT('#') && *uri != wxT('?'))
{ {
if(IsUnreserved(*uri) || IsSubDelim(*uri) || IsEscape(uri) || if(IsUnreserved(*uri) || IsSubDelim(*uri) ||
*uri == wxT('@') || *uri == wxT('/')) *uri == wxT('@') || *uri == wxT('/'))
m_path += *uri++; m_path += *uri++;
else if (IsEscape(uri))
{
m_path += *uri++;
m_path += *uri++;
m_path += *uri++;
}
else else
Escape(m_path, *uri++); Escape(m_path, *uri++);
} }
@@ -647,9 +668,15 @@ const wxChar* wxURI::ParsePath(const wxChar* uri, bool bReference, bool bNormali
{ {
while(*uri && *uri != wxT('#') && *uri != wxT('?')) while(*uri && *uri != wxT('#') && *uri != wxT('?'))
{ {
if(IsUnreserved(*uri) || IsSubDelim(*uri) || IsEscape(uri) || if(IsUnreserved(*uri) || IsSubDelim(*uri) ||
*uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/')) *uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/'))
m_path += *uri++; m_path += *uri++;
else if (IsEscape(uri))
{
m_path += *uri++;
m_path += *uri++;
m_path += *uri++;
}
else else
Escape(m_path, *uri++); Escape(m_path, *uri++);
} }
@@ -686,9 +713,15 @@ const wxChar* wxURI::ParseQuery(const wxChar* uri)
++uri; ++uri;
while(*uri && *uri != wxT('#')) while(*uri && *uri != wxT('#'))
{ {
if (IsUnreserved(*uri) || IsSubDelim(*uri) || IsEscape(uri) || if (IsUnreserved(*uri) || IsSubDelim(*uri) ||
*uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/') || *uri == wxT('?')) *uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/') || *uri == wxT('?'))
m_query += *uri++; m_query += *uri++;
else if (IsEscape(uri))
{
m_query += *uri++;
m_query += *uri++;
m_query += *uri++;
}
else else
Escape(m_query, *uri++); Escape(m_query, *uri++);
} }
@@ -711,9 +744,15 @@ const wxChar* wxURI::ParseFragment(const wxChar* uri)
++uri; ++uri;
while(*uri) while(*uri)
{ {
if (IsUnreserved(*uri) || IsSubDelim(*uri) || IsEscape(uri) || if (IsUnreserved(*uri) || IsSubDelim(*uri) ||
*uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/') || *uri == wxT('?')) *uri == wxT(':') || *uri == wxT('@') || *uri == wxT('/') || *uri == wxT('?'))
m_fragment += *uri++; m_fragment += *uri++;
else if (IsEscape(uri))
{
m_fragment += *uri++;
m_fragment += *uri++;
m_fragment += *uri++;
}
else else
Escape(m_fragment, *uri++); Escape(m_fragment, *uri++);
} }

View File

@@ -48,6 +48,7 @@ private:
CPPUNIT_TEST( BackwardsResolving ); CPPUNIT_TEST( BackwardsResolving );
CPPUNIT_TEST( Assignment ); CPPUNIT_TEST( Assignment );
CPPUNIT_TEST( Comparison ); CPPUNIT_TEST( Comparison );
CPPUNIT_TEST( Unescaping );
#if TEST_URL #if TEST_URL
CPPUNIT_TEST( URLCompat ); CPPUNIT_TEST( URLCompat );
#if wxUSE_PROTOCOL_HTTP #if wxUSE_PROTOCOL_HTTP
@@ -66,6 +67,7 @@ private:
void BackwardsResolving(); void BackwardsResolving();
void Assignment(); void Assignment();
void Comparison(); void Comparison();
void Unescaping();
#if TEST_URL #if TEST_URL
void URLCompat(); void URLCompat();
@@ -278,9 +280,30 @@ void URITestCase::Comparison()
CPPUNIT_ASSERT(wxURI(wxT("http://mysite.com")) == wxURI(wxT("http://mysite.com"))); CPPUNIT_ASSERT(wxURI(wxT("http://mysite.com")) == wxURI(wxT("http://mysite.com")));
} }
void URITestCase::Unescaping()
{
wxString orig = wxT("http://test.com/of/file%3A%2F%2FC%3A%5Curi%5C")
wxT("escaping%5Cthat%5Cseems%5Cbroken%5Csadly%5B1%5D.rss");
wxString works= wxURI(orig).BuildUnescapedURI();
CPPUNIT_ASSERT(orig.IsSameAs(works) == false);
wxString orig2 = wxT("http://test.com/of/file%3A%2F%")
wxT("2FC%3A%5Curi%5Cescaping%5Cthat%5Cseems%")
wxT("5Cbroken%5Csadly%5B1%5D.rss");
wxString works2 = wxURI::Unescape(orig2);
wxString broken2 = wxURI(orig2).BuildUnescapedURI();
CPPUNIT_ASSERT(works2.IsSameAs(broken2));
}
#if TEST_URL #if TEST_URL
#include "wx/url.h" #include "wx/url.h"
#include "wx/file.h"
void URITestCase::URLCompat() void URITestCase::URLCompat()
{ {
@@ -327,5 +350,6 @@ void URITestCase::URLProxy()
url.SetProxy(wxT("pserv:3122")); url.SetProxy(wxT("pserv:3122"));
} }
#endif // wxUSE_PROTOCOL_HTTP #endif // wxUSE_PROTOCOL_HTTP
#endif
#endif // TEST_URL