Bug 658242 - Search in bookmarks doesn't find javascript: bookmarks.

r=dietrich
This commit is contained in:
Marco Bonardo 2011-07-26 15:12:38 +02:00
Родитель 1842aa0536
Коммит 70185e1d10
6 изменённых файлов: 93 добавлений и 8 удалений

Просмотреть файл

@ -231,6 +231,7 @@ namespace places {
/* static */
void
MatchAutoCompleteFunction::fixupURISpec(const nsCString &aURISpec,
PRInt32 aMatchBehavior,
nsCString &_fixedSpec)
{
nsCString unescapedSpec;
@ -246,6 +247,9 @@ namespace places {
else
_fixedSpec.Assign(aURISpec);
if (aMatchBehavior == mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED)
return;
if (StringBeginsWith(_fixedSpec, NS_LITERAL_CSTRING("http://")))
_fixedSpec.Cut(0, 7);
else if (StringBeginsWith(_fixedSpec, NS_LITERAL_CSTRING("https://")))
@ -319,6 +323,7 @@ namespace places {
{
switch (aBehavior) {
case mozIPlacesAutoComplete::MATCH_ANYWHERE:
case mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED:
return findAnywhere;
case mozIPlacesAutoComplete::MATCH_BEGINNING:
return findBeginning;
@ -351,9 +356,12 @@ namespace places {
nsCString url;
(void)aArguments->GetUTF8String(kArgIndexURL, url);
PRInt32 matchBehavior = aArguments->AsInt32(kArgIndexMatchBehavior);
// We only want to filter javascript: URLs if we are not supposed to search
// for them, and the search does not start with "javascript:".
if (!HAS_BEHAVIOR(JAVASCRIPT) &&
if (matchBehavior != mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED &&
!HAS_BEHAVIOR(JAVASCRIPT) &&
!StringBeginsWith(searchString, NS_LITERAL_CSTRING("javascript:")) &&
StringBeginsWith(url, NS_LITERAL_CSTRING("javascript:"))) {
NS_ADDREF(*_result = new IntegerVariant(0));
@ -381,13 +389,12 @@ namespace places {
return NS_OK;
}
// Obtain our search function.
searchFunctionPtr searchFunction = getSearchFunction(matchBehavior);
// Clean up our URI spec and prepare it for searching.
nsCString fixedURI;
fixupURISpec(url, fixedURI);
// Obtain our search function.
PRInt32 matchBehavior = aArguments->AsInt32(kArgIndexMatchBehavior);
searchFunctionPtr searchFunction = getSearchFunction(matchBehavior);
fixupURISpec(url, matchBehavior, fixedURI);
nsCAutoString title;
(void)aArguments->GetUTF8String(kArgIndexTitle, title);

Просмотреть файл

@ -179,10 +179,14 @@ private:
*
* @param aURISpec
* The spec of the URI to prepare for searching.
* @param aMatchBehavior
* The matching behavior to use defined by one of the
* mozIPlacesAutoComplete::MATCH_* values.
* @param _fixedSpec
* An out parameter that is the fixed up string.
*/
static void fixupURISpec(const nsCString &aURISpec, nsCString &_fixedSpec);
static void fixupURISpec(const nsCString &aURISpec, PRInt32 aMatchBehavior,
nsCString &_fixedSpec);
};

Просмотреть файл

@ -73,6 +73,12 @@ interface mozIPlacesAutoComplete : nsISupports
*/
const long MATCH_BEGINNING = 3;
/**
* Match anywhere in each searchable term without doing any transformation
* or stripping on the underlying data.
*/
const long MATCH_ANYWHERE_UNMODIFIED = 4;
//////////////////////////////////////////////////////////////////////////////
//// Search Behavior Constants

Просмотреть файл

@ -5706,7 +5706,7 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const
clause.Condition("AUTOCOMPLETE_MATCH(").Param(":search_string")
.Str(", h.url, page_title, tags, ")
.Str(nsPrintfCString(17, "0, 0, 0, 0, %d, 0)",
mozIPlacesAutoComplete::MATCH_ANYWHERE).get());
mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED).get());
}
// min and max visit count

Просмотреть файл

@ -0,0 +1,67 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that bookmarklets are returned by searches with searchTerms.
let testData = [
{ isInQuery: true
, isBookmark: true
, title: "bookmark 1"
, uri: "http://mozilla.org/script/"
},
{ isInQuery: true
, isBookmark: true
, title: "bookmark 2"
, uri: "javascript:alert('moz');"
}
];
add_test(function test_seach_by_title()
{
let query = PlacesUtils.history.getNewQuery();
query.searchTerms = "bookmark";
let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
compareArrayToResult(testData, root);
root.containerOpen = false;
run_next_test();
});
add_test(function test_seach_by_schemeToken()
{
let query = PlacesUtils.history.getNewQuery();
query.searchTerms = "script";
let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
compareArrayToResult(testData, root);
root.containerOpen = false;
run_next_test();
});
add_test(function test_seach_by_uriAndTitle()
{
let query = PlacesUtils.history.getNewQuery();
query.searchTerms = "moz";
let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
compareArrayToResult(testData, root);
root.containerOpen = false;
run_next_test();
});
function run_test()
{
populateDB(testData);
run_next_test();
}

Просмотреть файл

@ -17,6 +17,7 @@ tail =
[test_results-as-visit.js]
[test_searchterms-domain.js]
[test_searchterms-uri.js]
[test_searchterms-bookmarklets.js]
[test_sort-date-site-grouping.js]
[test_sorting.js]
[test_tags.js]