diff --git a/frontend/apps/cloudstorage/webdavapi.lua b/frontend/apps/cloudstorage/webdavapi.lua index 7086ed0ca..57b782317 100644 --- a/frontend/apps/cloudstorage/webdavapi.lua +++ b/frontend/apps/cloudstorage/webdavapi.lua @@ -59,7 +59,7 @@ function WebDavApi:listFolder(address, user, pass, folder_path) local has_trailing_slash = false local has_leading_slash = false - if string.sub( address, -1 ) ~= "/" then has_trailing_slash = true end + if string.sub( address, -1 ) == "/" then has_trailing_slash = true end if path == nil or path == "/" then path = "" elseif string.sub( path, 1, 2 ) == "/" then @@ -73,6 +73,9 @@ function WebDavApi:listFolder(address, user, pass, folder_path) address = address .. "/" end local webdav_url = address .. path + if not has_trailing_slash then + webdav_url = webdav_url .. "/" + end local request, sink = {}, {} local parsed = url.parse(webdav_url) @@ -96,19 +99,20 @@ function WebDavApi:listFolder(address, user, pass, folder_path) end local res_data = table.concat(sink) + if res_data ~= "" then -- iterate through the tags, each containing an entry - for item in res_data:gmatch("(.-)") do + for item in res_data:gmatch("<[^:]*:response[^>]*>(.-)") do --logger.dbg("WebDav catalog item=", item) -- is the path and filename of the entry. - local item_fullpath = item:match("(.*)") + local item_fullpath = item:match("<[^:]*:href[^>]*>(.*)") if string.sub( item_fullpath, -1 ) == "/" then item_fullpath = string.sub( item_fullpath, 1, -2 ) end local is_current_dir = self:isCurrentDirectory( item_fullpath, address, path ) local item_name = util.urlDecode( FFIUtil.basename( item_fullpath ) ) local item_path = path .. "/" .. item_name - if item:find("") then + if item:find("<[^:]*:collection/>") then item_name = item_name .. "/" if not is_current_dir then table.insert(webdav_list, { @@ -117,7 +121,7 @@ function WebDavApi:listFolder(address, user, pass, folder_path) type = "folder", }) end - elseif item:find("") and (DocumentRegistry:hasProvider(item_name) + elseif item:find("<[^:]*:resourcetype/>") and (DocumentRegistry:hasProvider(item_name) or G_reader_settings:isTrue("show_unsupported")) then table.insert(webdav_file, { text = item_name,