Dir listing: special-case ".." to come first.

Suggested by: @frogtile

Fixes #14
This commit is contained in:
Emil Mikulic
2022-01-19 20:10:50 +11:00
parent f0ca481fd1
commit 3641c2f50f
3 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,7 @@ runtests() {
rm -rf $DIR || exit 1
fi
mkdir $DIR || exit 1
mkdir $DIR/\( || exit 1
mkdir $DIR/forbidden || exit 1
chmod 0 $DIR/forbidden || exit 1
mkdir $DIR/unreadable || exit 1

View File

@ -174,6 +174,15 @@ class TestDirList(TestHelper):
self.assertEqual(ord("#"), 0x23)
self.assertContains(body, "escape%28this%29name", "12345")
def test_dotdot_first(self):
resp = self.get("/")
status, hdrs, body = parse(resp)
self.assertLess(b'(', b'..') # ( sorts before ..
paren_pos = body.index(b'<a href="%28">(</a>/')
dotdot_pos = body.index(b'<a href="..">..</a>/')
# But we special-case .. to come first
self.assertLess(dotdot_pos, paren_pos)
class TestCases(TestHelper):
pass # these get autogenerated in setUpModule()