b9bf34a94aad

Send requests with empty path or non-markdown files to "file" command.
[view raw] [browse files]
author Chris Eldredge <chris.eldredge@gmail.com>
date Fri, 10 Aug 2012 22:41:36 +0100
parents 1d3416da68e0
children f605dfaddcc9
branches/tags (none)
files __init__.py

Changes

diff -r 1d3416da68e0 -r b9bf34a94aad __init__.py
--- a/__init__.py	Thu Aug 09 23:47:58 2012 +0100
+++ b/__init__.py	Fri Aug 10 22:41:36 2012 +0100
@@ -11,16 +11,19 @@
 logging.basicConfig()
 
 def filerevision_markdown(web, req, tmpl):
-	f = req.form.get('file', [''])[0]
-	parts = os.path.splitext(f)
+	path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
+	parts = os.path.splitext(path)
+
+	if not parts[1] == '.markdown' and not parts[1] == '.md':
+		return webcommands.file(web, req, tmpl)
 		
-	if not parts[1] == '.markdown' and not parts[1] == '.md':
-		return rawfile(web, req, tmpl)
+	if not path:
+		return webcommands.file(web, req, tmpl)
 	
 	previewMode = 'node' in req.form and req.form['node'][0] == '_preview'
 	
 	if previewMode:
-		text = file(web.repo.root + "/" + f).read()
+		text = file(web.repo.root + "/" + path).read()
 	else:
 		fctx = webutil.filectx(web.repo, req)
 		text = fctx.data()
@@ -32,9 +35,9 @@
 	md = markdown.Markdown(extensions=['wikilinks(base_url={0},end_url={1})'.format('', parts[1])])	
 	html = md.convert(text)
 	
-	args = {'file':f,
+	args = {'file':path,
 			'readmefilename':parts[0].split('/')[-1],
-			'path':webutil.up(f),
+			'path':webutil.up(path),
 			'readme':html}
 
 	if previewMode: