From e668379f6d57851f14af2f1c3e494c90e5eebb25 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Thu, 22 Aug 2013 11:42:21 -0300 Subject: [PATCH] Fix crash when trying to go to / on FM Deals with more cases in FileChooser:compressPath, including `/mnt/..`. --- frontend/ui/widget/filechooser.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index d52f0c686..5fbb32f27 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -15,18 +15,18 @@ function FileChooser:init() Menu.init(self) -- call parent's init() end -function FileChooser:compressPath(item_path) - if (item_path:sub(1, 1) == ".") then - -- ignore relative path - return item_path +function FileChooser:compressPath(path) + local pos + if path:sub(1, 1) ~= "/" then + -- currently does not work with relative paths + return path end - + path = path:gsub("/+", "/") -- compress paths like "test/pdf/../epub" into "test/epub" - local path = item_path - while path:match("/[^/]+[/][\\.][\\.]") do - path = path:gsub("/[^/]+[/][\\.][\\.]", "") - end - return path + repeat + path, pos = path:gsub("/?[^/]*/%.%.", "", 1) + until pos == 0 + return path ~= "" and path or "/" end function FileChooser:genItemTableFromPath(path)