refactor: improved protocol matching patterns

ref #605
This commit is contained in:
tomasklaen
2023-08-16 12:52:07 +02:00
parent f857d468e1
commit 68b5b2aaed
2 changed files with 2 additions and 2 deletions

View File

@@ -319,7 +319,7 @@ end
-- Check if path is a protocol, such as `http://...`.
---@param path string
function is_protocol(path)
return type(path) == 'string' and (path:find('^%a[%a%d-_]+://') ~= nil or path:find('^%a[%a%d-_]+:%?') ~= nil)
return type(path) == 'string' and (path:find('^%a[%w.+-]-://') ~= nil or path:find('^%a[%w.+-]-:%?') ~= nil)
end
---@param path string

View File

@@ -969,7 +969,7 @@ bind_command('playlist', create_self_updating_menu_opener({
serializer = function(playlist)
local items = {}
for index, item in ipairs(playlist) do
local is_url = item.filename:find('://')
local is_url = is_protocol(item.filename)
local item_title = type(item.title) == 'string' and #item.title > 0 and item.title or false
items[index] = {
title = item_title or (is_url and item.filename or serialize_path(item.filename).basename),