From df9fd3e88522cc54d93c49b57d0b33abc67422af Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Sat, 4 Dec 2004 22:38:54 +0000 Subject: [PATCH] Bug 261608 only search for colon in the first word of a string when checking whether we have a url or keyword patch by Jeff Walden (remove +bmo to email) r=caillon sr=darin no tp affect - checking in again git-svn-id: svn://10.0.0.236/trunk@166254 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDefaultURIFixup.cpp | 52 +++++++++------------ 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/mozilla/docshell/base/nsDefaultURIFixup.cpp b/mozilla/docshell/base/nsDefaultURIFixup.cpp index b8ca485493e..f708510504b 100644 --- a/mozilla/docshell/base/nsDefaultURIFixup.cpp +++ b/mozilla/docshell/base/nsDefaultURIFixup.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Adam Lock + * Jeff Walden * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -695,44 +696,33 @@ nsresult nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString, // These are keyword formatted strings // "what is mozilla" // "what is mozilla?" - // "?mozilla" - // "?What is mozilla" + // "docshell site:mozilla.org" - has no dot/colon in the first space-separated substring + // "?mozilla" - anything that begins with a question mark + // "?site:mozilla.org docshell" // These are not keyword formatted strings - // "www.blah.com" - anything with a dot in it - // "nonQualifiedHost:80" - anything with a colon in it + // "www.blah.com" - first space-separated substring contains a dot, doesn't start with "?" + // "www.blah.com stuff" + // "nonQualifiedHost:80" - first space-separated substring contains a colon, doesn't start with "?" + // "nonQualifiedHost:80 args" // "nonQualifiedHost?" // "nonQualifiedHost?args" // "nonQualifiedHost?some args" - if(aURIString.FindChar('.') == -1 && aURIString.FindChar(':') == -1) + PRInt32 dotLoc = aURIString.FindChar('.'); + PRInt32 colonLoc = aURIString.FindChar(':'); + PRInt32 spaceLoc = aURIString.FindChar(' '); + PRInt32 qMarkLoc = aURIString.FindChar('?'); + + if ((dotLoc == kNotFound || (spaceLoc > 0 && spaceLoc < dotLoc)) && + (colonLoc == kNotFound || (spaceLoc > 0 && spaceLoc < colonLoc)) && + (spaceLoc > 0 && (qMarkLoc == kNotFound || spaceLoc < qMarkLoc)) || + qMarkLoc == 0) { - PRInt32 qMarkLoc = aURIString.FindChar('?'); - PRInt32 spaceLoc = aURIString.FindChar(' '); - - PRBool keyword = PR_FALSE; - if(qMarkLoc == 0) - keyword = PR_TRUE; - else if((spaceLoc > 0) && ((qMarkLoc == -1) || (spaceLoc < qMarkLoc))) - keyword = PR_TRUE; - - if(keyword) - { - nsCAutoString keywordSpec("keyword:"); - char *utf8Spec = ToNewCString(aURIString); // aURIString is UTF-8 - if(utf8Spec) - { - char* escapedUTF8Spec = nsEscape(utf8Spec, url_Path); - if(escapedUTF8Spec) - { - keywordSpec.Append(escapedUTF8Spec); - NS_NewURI(aURI, keywordSpec.get(), nsnull); - nsMemory::Free(escapedUTF8Spec); - } // escapedUTF8Spec - nsMemory::Free(utf8Spec); - } // utf8Spec - } // keyword - } // FindChar + nsCAutoString keywordSpec("keyword:"); + keywordSpec.Append(aURIString); + NS_NewURI(aURI, keywordSpec); + } if(*aURI) return NS_OK;