From 980fea6c8d23a0a4d871c661a5749860cc571343 Mon Sep 17 00:00:00 2001 From: Pierce Date: Sat, 12 Aug 2023 17:45:40 -0400 Subject: [PATCH] add invalid date test cases for address parsing functions --- lua/cfc_http_restrictions/default_config.lua | 4 +--- lua/cfc_http_restrictions/shared/url.lua | 4 ++-- lua/tests/cfc_cl_http_whitelist/url.lua | 11 ++++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lua/cfc_http_restrictions/default_config.lua b/lua/cfc_http_restrictions/default_config.lua index f8bbc65..d6b4173 100644 --- a/lua/cfc_http_restrictions/default_config.lua +++ b/lua/cfc_http_restrictions/default_config.lua @@ -2,14 +2,12 @@ AddCSLuaFile() ---@alias WhitelistAddressOption { allowed: boolean|nil, noisy: boolean|nil, permanent: boolean|nil } ----@class WhitelistConfig +---@class WhitelistConfig ---@field version string ---@field wrapHTMLPanels boolean|nil ---@field defaultAssetURIOptions WhitelistAddressOption ---@field defaultOptions WhitelistAddressOption ---@field addresses table - ----@type WhitelistConfig local config = { version = "1", -- this field allows backwards compatibility if the config structure is ever updated diff --git a/lua/cfc_http_restrictions/shared/url.lua b/lua/cfc_http_restrictions/shared/url.lua index cd3f388..3191f68 100644 --- a/lua/cfc_http_restrictions/shared/url.lua +++ b/lua/cfc_http_restrictions/shared/url.lua @@ -36,8 +36,9 @@ end local parsedAddressCache = {} ---@parm url string ----@return string +---@return string|nil function CFCHTTP.GetAddress( url ) + if not url then return end local cached = parsedAddressCache[url] if cached then return cached end @@ -50,4 +51,3 @@ end function CFCHTTP.IsAssetURI( url ) return string.StartWith( url, "asset://" ) end - diff --git a/lua/tests/cfc_cl_http_whitelist/url.lua b/lua/tests/cfc_cl_http_whitelist/url.lua index 0385fa7..59f1067 100644 --- a/lua/tests/cfc_cl_http_whitelist/url.lua +++ b/lua/tests/cfc_cl_http_whitelist/url.lua @@ -4,6 +4,8 @@ local testUrls = { { url = "https://fox.pics:8080/0d875a97-2ab3-489c-b7db-d9d9f026504e.jpg", address = "fox.pics" }, { url = "https://cfcservers.org", address = "cfcservers.org" }, { url = "https://24.321.483.222", address = "24.321.483.222" }, + { url = "nil", address = nil }, + { url = nil, address = nil }, } local htmlBlobs = [[ @@ -28,9 +30,12 @@ return { for _, urlData in pairs( testUrls ) do local html = htmlBlobs:format( urlData.url ) local urls = CFCHTTP.FileTypes.HTML.GetURLSFromData( html ) - - expect( #urls ).to.equal( 1 ) - expect( urls[1] ).to.equal( urlData.url ) + if urlData.address then + expect( #urls ).to.equal( 1 ) + expect( urls[1] ).to.equal( urlData.url ) + else + expect( #urls ).to.equal( 0 ) + end end end },