Skip to content

Commit

Permalink
handle file:// protocol URI scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Sep 1, 2019
1 parent 3a957d7 commit 3eb5103
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions reader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,27 @@ SettingsMigration:migrateSettings(G_reader_settings)

local exit_code

local function getPathFromURI(str)
local hexToChar = function(x)
return string.char(tonumber(x, 16))
end

local unescape = function(url)
return url:gsub("%%(%x%x)", hexToChar)
end

local prefix = "file://"
if str:sub(1, #prefix) ~= prefix then
return str
end
return unescape(str):sub(#prefix+1)
end

if ARGV[argidx] and ARGV[argidx] ~= "" then
local file
if lfs.attributes(ARGV[argidx], "mode") == "file" then
file = ARGV[argidx]
local sanitized_path = getPathFromURI(ARGV[argidx])
if lfs.attributes(sanitized_path, "mode") == "file" then
file = sanitized_path
elseif open_last and last_file then
file = last_file
end
Expand Down

0 comments on commit 3eb5103

Please sign in to comment.