Closed Bug 232223 Opened 21 years ago Closed 18 years ago

encodeURIComponent() may result in garbage

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 314456

People

(Reporter: p_ch, Unassigned)

Details

that's a followup from bug 228103. The problem is not that trivial, there's some funkiness around. I ran some systematic tests and I'll synthesize them here: 1) EncodeURIComponents("") seems to return the empty string (typeof: string, length: 0, dump:nothing) but when it is passed in (mozilla/browser/base/content/search.xml): searchURL = ISEARCHSVC.GetInternetSearchURL(this.currentEngine, encodeURIComponent(""), 0, 0, {value:0}); then searchURL contains garbage characters. whereas: s/encodeURIComponent("")/"" does not ! 2) I was surprized that encodeURIComponent(null) returns the "null" string instead of the empty string or null. But that's apparently following the spec Ecma-262 15.1.3.4 which makes a call to ToString. 3) but then the cases: given var a,b={}; a=null; b.value=null; this.value=null; - s/encodeURIComponent("")/encodeURIComponent(null) - s/encodeURIComponent("")/encodeURIComponent(a) - s/encodeURIComponent("")/encodeURIComponent(b.value) will return a query with "null" as per 2 but the case: - s/encodeURIComponent("")/encodeURIComponent(this.value) will result in garbage...
cc'ing Brendan for his advice. Note this is a follow-up to bug 228103. To summarize: in the file mozilla/browser/base/content/search.xml, the following two calls should be equivalent: ISEARCHSVC.GetInternetSearchURL(..., encodeURIComponent(""), ...) ISEARCHSVC.GetInternetSearchURL(..., "", ...) Yet the first outputs garbage characters, whereas the second does not. Also note the reporter's interesting variation in 3) above using |null|. Note how |ISEARCHSVC| is defined earlier in the file: var ISEARCHSVC = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"] .getService(Components.interfaces.nsIInternetSearchService); Is it possible that the bug might be caused by this component and its |GetInternetSearchURL()| method, rather than by any bug in the JS method |encodeURIComponent()|? As the reporter notes, |encodeURIComponent("")| returns the empty string every time we try it independently. I have also tried incorporating it into JS functions, and continue to get the empty string as expected. For example, I ran this script successfully in the current JS shell: function F(obj1, str, int1, int2, obj2) { var ret = ''; ret += 'The return value is: "'; ret += str; ret += '"\nlength = '; ret += str.length; return ret; } var ISEARCHSVC = {}; ISEARCHSVC.GetInternetSearchURL = F; var searchURL = ISEARCHSVC.GetInternetSearchURL({}, encodeURIComponent(""), 0, 0, {value:0} ); print(searchURL);
Summary: encodeURIComponent may result in garbage → encodeURIComponent() may result in garbage
-> default qa
QA Contact: pschwartau → general
Is this still a problem? If so, this should probably block the next set of security releases....
(In reply to comment #1) > Is it possible that the bug might be caused by this component > and its |GetInternetSearchURL()| method, rather than by any bug > in the JS method |encodeURIComponent()|? Not only possible, I'd say it's highly likely.
This looks a lot like bug 314456 which added empty string protection to the encodeURI* and decodeURI* functions. Marking the duplicateness. *** This bug has been marked as a duplicate of 314456 ***
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.