mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
fix(reader): sanitize KOReader device download paths
Use KOReader's destination filesystem rules for each server-provided path segment so Kindle downloads reject invalid names without changing Linux-compatible names. Preserve bulk collision handling after sanitization. Fixes #1203
This commit is contained in:
@@ -28,12 +28,16 @@ local safeFilenameBase = CatalogUtil.safeFilenameBase
|
||||
|
||||
local CatalogDownload = {}
|
||||
|
||||
local function sanitizeDevicePath(device_path)
|
||||
local function sanitizeDevicePath(device_path, download_dir)
|
||||
local normalized = tostring(device_path or ""):gsub("\\", "/"):gsub("^/+", "")
|
||||
local segments = {}
|
||||
for segment in normalized:gmatch("[^/]+") do
|
||||
if segment == ".." then return nil end
|
||||
if segment ~= "." then table.insert(segments, segment) end
|
||||
if segment ~= "." then
|
||||
local safe_segment = util.getSafeFilename(segment, download_dir)
|
||||
if not safe_segment or safe_segment == "" or safe_segment == "." or safe_segment == ".." then return nil end
|
||||
table.insert(segments, safe_segment)
|
||||
end
|
||||
end
|
||||
if #segments == 0 then return nil end
|
||||
return table.concat(segments, "/")
|
||||
@@ -44,7 +48,7 @@ local function joinDownloadPath(download_dir, relative_path)
|
||||
end
|
||||
|
||||
local function resolveRelativeDownloadPath(download_dir, filename, filetype, device_path, filename_override)
|
||||
local relative = sanitizeDevicePath(device_path)
|
||||
local relative = sanitizeDevicePath(device_path, download_dir)
|
||||
if relative and not filename_override then return relative end
|
||||
|
||||
local parent = relative and relative:match("^(.*)/[^/]+$")
|
||||
|
||||
@@ -48,7 +48,7 @@ local BookOrbitProgressSync = require("bookorbit_progress_sync")
|
||||
local BookOrbitSweep = require("bookorbit_sweep")
|
||||
local BookOrbitUpdater = require("bookorbit_updater")
|
||||
|
||||
local PLUGIN_VERSION = "1.5.1"
|
||||
local PLUGIN_VERSION = "1.5.2"
|
||||
|
||||
local SYNC_STRATEGY = {
|
||||
PROMPT = 1,
|
||||
|
||||
Reference in New Issue
Block a user