From 6c4248251c968c27ff33fe75d8afa8660b16958a Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 15:24:10 +0800 Subject: [PATCH] compress paths like "test/pdf/../epub" into "test/epub" in FileChooser This patch fixes Bug #107 --- frontend/ui/widget/filechooser.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 589d69b92..38d70bbff 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -13,7 +13,17 @@ function FileChooser:init() self:changeToPath(self.path) end +function FileChooser:compressPath(item_path) + -- compress paths like "test/pdf/../epub" into "test/epub" + local path = item_path + while path:match("/[^/]+[/][\\.][\\.]") do + path = path:gsub("/[^/]+[/][\\.][\\.]", "") + end + return path +end + function FileChooser:changeToPath(path) + path = self:compressPath(path) local dirs = {} local files = {} self.path = path