Last Comment Bug 506511 - Web searches in sidebar pass symbols rather than spaces to the search engines
: Web searches in sidebar pass symbols rather than spaces to the search engines
: fixed-seamonkey2.0.5, regression
Product: SeaMonkey
Classification: Client Software
Component: Search (show other bugs)
: Trunk
: All All
-- normal (vote)
: ---
Assigned To:
Depends on:
  Show dependency treegraph
Reported: 2009-07-26 00:23 PDT by _\/_ Luctur _\/_
Modified: 2010-04-11 15:55 PDT (History)
5 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---

Patch v1.0 wallpaper over the problem. (1.18 KB, patch)
2010-03-25 21:31 PDT, Philip Chee
no flags Details | Diff | Splinter Review
Patch v1.1 only escape (1.21 KB, application/octet-stream)
2010-03-26 08:14 PDT, Philip Chee
no flags Details
Patch v1.1 only escape '+' in the path (1.21 KB, patch)
2010-03-26 08:17 PDT, Philip Chee
jh: feedback+
Details | Diff | Splinter Review
%2B or not %2B? (2.37 KB, patch)
2010-03-31 08:06 PDT,
no flags Details | Diff | Splinter Review
Revised patch (2.44 KB, patch)
2010-03-31 08:58 PDT,
iann_bugzilla: review+
kairo: approval‑seamonkey2.0.5+
Details | Diff | Splinter Review

Description User image _\/_ Luctur _\/_ 2009-07-26 00:23:20 PDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20090717 SeaMonkey/2.0b1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20090717 SeaMonkey/2.0b1

SM passes spaces to search engines as symbols % (percentage) and +25 rather than actual spaces.


Reproducible: Always

Steps to Reproduce:
1. open SM sidebar;
2. search for a couple of words separated by spaces (i.e. "Name Surname"); 
3. do your web search;
4. click the "Next" button in the sidebar search tab and display more results.
Actual Results:  
After the search, SM displays wrong search engine results.

Expected Results:  
SM correctly displays search engines results either in sidebar and in main page tab.

I have Google as default search engine and in the sidebar input field I've written my name "Gianluca Turconi".

After the search, the input field displays "Gianluca%Turconi", but so far there's no problem because Google finds correctly the first page of results. When I press the "next" button in SM sidebar the input text changes to "gianluca+25turconi" and the search returns wrong results. 

Sometimes (3 out of 10 attempts), the wrong search string was passed to the wrong search engine too (Ask instead of Google).

The web search results are correctly displayed both in sidebar and the Google main html page if I click "next" on Google web page only.

More details from Jens Hatlak:

The first field value change is already wrong, it shouldn't replace the space by a percent sign. I tracked that part down to search-panel.js function rememberSearchText(). In line 128 'target' is already wrong, containing %25 instead of a space. %25 gets decoded to % by decodeURIComponent() in line 142. There's even a plus-to-space conversion in line 130 but obviously it doesn't apply here.

rememberSearchText() is called from RDF_observer. Maybe this regression is a side-effect of some RDF-related changes?

BTW: The second part of the steps above can also be produced by simply repeating the search instead of pressing Next.
Comment 1 User image Jens Hatlak (:InvisibleSmiley) 2009-07-26 15:53:47 PDT
Further analysis shows that RDF_observer's onChange() (in combination with prop == textArc which is LastText) is only triggered by RememberLastSearchText() (see nsInternetSearchService.cpp). That function is only called on three occasions:

1. by search-panel.js's OpenSearch(), line 841, with the correct value, but with sidebarInitiatedSearch == true so rememberSearchText() does nothing,

2. by nsInternetSearchService.cpp's FindInternetSearchResults(), line 2719, with nsnull, which should clear the search text but is not called in this case,

3. by nsInternetSearchService.cpp's FindInternetSearchResults(), line 2701, obviously with the wrong value since the two other cases above have been eliminated.

Maybe a regression from bug 374862? Don't expect me to understand any of those C++ changes... Unfortunately I have to give up here. Hopefully someone else can take over.
Comment 2 User image Robert Kaiser 2010-03-25 09:14:07 PDT
I would very much hope for us to switch to the toolkit search service for 2.1, but I guess someone would need to rewrite that sidebar in that case...
Comment 3 User image Philip Chee 2010-03-25 21:31:57 PDT
Created attachment 435091 [details] [diff] [review]
Patch v1.0 wallpaper over the problem.

The real problem is somewhere in the CPP implementation of nsIInternetSearchService::FindInternetSearchResults(). There is a lot of escape/unescape/escape/unescape going on there and I guess something got lost in between.

This wallpapers over the problem in the front end until the search service is rewritten to use the toolkit openSearch implementation.
Comment 4 User image Philip Chee 2010-03-26 07:04:10 PDT
Comment on attachment 435091 [details] [diff] [review]
Patch v1.0 wallpaper over the problem.

Oops. Spotted an obvious problem.
Comment 5 User image Philip Chee 2010-03-26 08:14:50 PDT
Created attachment 435177 [details]
Patch v1.1 only escape
Comment 6 User image Philip Chee 2010-03-26 08:17:59 PDT
Created attachment 435179 [details] [diff] [review]
Patch v1.1 only escape '+' in the path

Only convert + to space in the path.
Comment 7 User image Jens Hatlak (:InvisibleSmiley) 2010-03-26 14:40:58 PDT
Comment on attachment 435179 [details] [diff] [review]
Patch v1.1 only escape '+' in the path

Works fine. :-) Tried:
1. entered search string with spaces, pressed Search, Next, Previous.
2. entered search string with spaces and +s, pressed Search, Next, Previous.
In both cases the text field (Sidebar) and Google's text field (browsing area) matched what I had entered before and after each button press.
Comment 8 User image 2010-03-31 08:06:43 PDT
Created attachment 436193 [details] [diff] [review]
%2B or not %2B?

OK, so the bug was with the external string API conversion.

Historically the code converted %25 to %2B25 and + to %25 before converting them from the search engine's character set to UTF8, and then converted them back.

Unfortunately the external string API conversion suffered from too much copy and paste and the wrong string was converted back.

Additionally (and this applied to the original code) the strings %25 and %2B were confused. %2B is the encoding of +, and %252B is the encoding of %2B.

So of course I couldn't choose any other patch description ;-)
Comment 9 User image 2010-03-31 08:58:54 PDT
Created attachment 436203 [details] [diff] [review]
Revised patch

Although %2B25 didn't work with the old code %252B doesn't work either (searching for +25 %25 25 +2B %2B 2B fails differently depending on the code).
Comment 10 User image Ian Neal 2010-04-05 07:48:42 PDT
Comment on attachment 436203 [details] [diff] [review]
Revised patch

r=me but, unless there is a reason that currently escapes me (pun intended), can you be consistent with the single and double quotes used.
Comment 11 User image 2010-04-05 14:11:41 PDT
(In reply to comment #10)
> (From update of attachment 436203 [details] [diff] [review])
> r=me but, unless there is a reason that currently escapes me (pun intended),
> can you be consistent with the single and double quotes used.
This is C++, so you use single quotes for a single character and double quotes for an arbitrary-length string. Now I guess I could have used Find to find a single-character string, but it's more efficient to use FindChar. Replace is overloaded and will accept both, but I stuck to matching the strings I found.
Comment 12 User image 2010-04-05 14:17:47 PDT
Pushed changeset eada20ef2a0a to comm-central.
Comment 13 User image 2010-04-11 15:55:47 PDT
Pushed changeset 2bed1d09c66a to releases/comm-1.9.1

Note You need to log in before you can comment on or make changes to this bug.