Closed Bug 368211 Opened 18 years ago Closed 18 years ago

Pretty generated directory listings for directories not containing index.html

Categories

(Testing :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Waldo, Assigned: Waldo)

Details

Attachments

(1 file)

If I have /path/to/dir/ -> http://localhost:8080/ and /path/to/dir/ doesn't contain an index.html file, it would be nice to see a directory listing. I have mostly-working support done which I'll post probably later today, after I write some minimal tests for it (yes, believe it or not, I did run into an issue or two).
Attached patch PatchSplinter Review
The mentioned issues mostly relate to escaping -- in the initial patch I was outputting the href attributes of links with single-quoting, but encodeURIComponent ignores ' in URLs. It'd escape >/< so you couldn't smuggle valid HTML into the page, but with the right file and with HTML parsing what it is you *might* have been able to get invalid stuff into the page in some manner that would screw up page display. I switched to double-quoting because encodeURIComponent converts " to the urlencoded equivalent. This is more useful for debugging purposes than for anything else, and even then the only user of the server that uses indexes defines its own index handler, so feel free not to worry *too* much about an in-depth review if you don't want to -- I'm mostly looking for a sanity check and not much more.
Attachment #252937 - Flags: review?(sayrer)
Comment on attachment 252937 [details] [diff] [review] Patch >Index: netwerk/test/httpserver/httpd.js >+ var fileList = []; >+ var files = directory.directoryEntries; >+ while (files.hasMoreElements()) >+ fileList.push(files.getNext().QueryInterface(Ci.nsIFile)); >+ >+ fileList.sort(fileSort); >+ >+ for (var i = 0; i < fileList.length; i++) >+ { >+ var file = fileList[i]; >+ try >+ { >+ if (file.isHidden()) >+ continue; I would filter hidden files outside the loop, above the sort. Either fileList = [f for (f in fileList) if (!f.isHidden())] or fileList = fileList.filter(function (f) { return !f.isHidden(); }); >Index: netwerk/test/httpserver/test/test_default_index_handler.js >+/** >+ * Get child elements of elt with the given name in an ordered list. >+ */ >+function getChildren(elt, name) >+{ >+ var rv = []; >+ var kids = elt.childNodes; >+ for (var i = 0; i < kids.length; i++) >+ { >+ var kid = kids.item(i); // can't use [i] because no classinfo >+ if (kid.nodeType == 1 && // no Node object either >+ kid.nodeName == name) >+ rv.push(kid); >+ } >+ return rv; >+} Can you use getElementsByTagName instead? r=sayrer
Attachment #252937 - Flags: review?(sayrer) → review+
(In reply to comment #2) > I would filter hidden files outside the loop, above the sort. I added the filtering in the loop over the directoryEntries enumerator. > Can you use getElementsByTagName instead? I'd originally thought no, but on trying again I realized I was QIing to the wrong interface (nsIDOM3Node, not nsIDOMElement). I changed the patch to do this and added the requisite bunch of QI/item calls to make it work. Patch checked in, with requested changes.
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Moving httpd.js bugs to the new Testing :: httpd.js component; filter out this bugmail by searching for "ICanHasHttpd.jsComponent".
Component: Testing → httpd.js
Flags: in-testsuite+
Product: Core → Testing
Target Milestone: mozilla1.9alpha1 → ---
Version: Trunk → unspecified
...and changing the QA contact as well. Filter on the string "BugzillaQAContactHandlingIsStupid".
QA Contact: testing → httpd.js
Flags: in-testsuite+
Component: httpd.js → General
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: