Closed Bug 336456 Opened 18 years ago Closed 18 years ago

Add Search Engine with https:// in URL does not add to search box

Categories

(Firefox :: Search, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 267487

People

(Reporter: phreek86, Unassigned)

References

()

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3

If you go to https://addons.mozilla.org/search-engines.php and try to add an engine to the search bar, it won't work. The reason for this is because these URLs use https instead of http. 

An open issue on this was resolved for the wrong reasons and the supplied solutions did not fix the problem (bug <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=335602">335602</a>). The resolution claims that the article below fixes the issue but it does not address THIS problem.

http://kb.mozillazine.org/Search_engines_disappear_from_Search_Bar (does not fix problem)

Everyone I have asked to try adding an engine at the site listed above has had the same problems and get the same errors in the error console. Other people have reported the same issue on this board but the issues just get resolved citing the WRONG SOLUTIONS.

Reproducible: Always

Steps to Reproduce:
1. Go to https://addons.mozilla.org/search-engines.php
2. Click a search engine to add

Actual Results:  
Error console shows these errors:

[Exception... "Not enough arguments [nsIPromptService.alert]" nsresult:
"0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame ::
file:///C:/PROGRA~1/MOZILL~1/components/nsSidebar.js :: anonymous :: line 164"
data: no]

uncaught exception: [Exception... "Not enough arguments
[nsIPromptService.alert]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)"
location: "JS frame :: file:///C:/PROGRA~1/MOZILL~1/components/nsSidebar.js ::
anonymous :: line 164" data: no]

Expected Results:  
Add search engine

I have tracked down the source of this problem and fixed it. The errors in the error console are addressed in bug <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=268370">268370</a>.

As for the search engine not adding, this is another simple JavaScript issue...

The addSearchEngine method in nsSidebar.js checks the icon and engine source URLs to see that they're using HTTP (checks that 'http://' is in the URL string). Well, URLs on https://addons.mozilla.org/search-engines.php use HTTPS instead of HTTP. I changed those check to check for both 'http://' AND 'https://'

Now, if you apply the patch, restart Firefox, visit https://addons.mozilla.org/search-engines.php, and add an engine, it works!!!




Below is the code block that fixes the issue in nsSidebar.js:

    debug("addSearchEngine(" + engineURL + ", " + iconURL + ", " +
          suggestedCategory + ", " + suggestedTitle + ")");

    try
    {
        // make sure using HTTP (for both engine as well as icon URLs)

        if (engineURL.search(/(^http:|^https:)\/\//i) == -1)
        {
            debug ("must use HTTP to fetch search engine file");
            throw Components.results.NS_ERROR_INVALID_ARG;
        }
        
        if (iconURL.search(/^(^http:|^https:)\/\//i) == -1)
        {
            debug ("must use HTTP to fetch search icon file");
            throw Components.results.NS_ERROR_INVALID_ARG;
        }

        // make sure engineURL refers to a .src file
        if (engineURL.search(/\.src$/i) == -1)
        {
            debug ("engineURL doesn't reference a .src file");
            throw Components.results.NS_ERROR_INVALID_ARG;
        }

        // make sure iconURL refers to a .gif/.jpg/.jpeg/.png file
        if (iconURL.search(/\.(gif|jpg|jpeg|png)$/i) == -1)
        {
            debug ("iconURL doesn't reference a supported image file");
            throw Components.results.NS_ERROR_INVALID_ARG;
        }
    }
    catch(ex)
    {
        this.promptService.alert(null, "Error", "Failed to add the search engine.");
        throw Components.results.NS_ERROR_INVALID_ARG;
    }
Attached file Fixed nsSidebar.js
C:\Program Files\Mozilla Firefox\components\nsSidebar.js
Attachment #220667 - Attachment is patch: false

*** This bug has been marked as a duplicate of 267487 ***
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: