From 9e3e15846b94de255d384375fb8054b75fdc2d45 Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Wed, 19 Apr 2023 15:12:50 -0400 Subject: [PATCH] validate server URL before using it - fixes crash log on line 44 and 62 --- source/api/baserequest.brs | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/source/api/baserequest.brs b/source/api/baserequest.brs index f605bf51..33040d34 100644 --- a/source/api/baserequest.brs +++ b/source/api/baserequest.brs @@ -35,13 +35,15 @@ function buildParams(params = {} as object) as string return param_array.join("&") end function -function buildURL(path as string, params = {} as object) as string +function buildURL(path as string, params = {} as object) as dynamic + serverURL = get_url() + if serverURL = invalid then return invalid ' Add intial '/' if path does not start with one if path.Left(1) = "/" - full_url = get_url() + path + full_url = serverURL + path else - full_url = get_url() + "/" + path + full_url = serverURL + "/" + path end if if params.count() > 0 @@ -51,17 +53,19 @@ function buildURL(path as string, params = {} as object) as string return full_url end function -function APIRequest(url as string, params = {} as object) +function APIRequest(url as string, params = {} as object) as dynamic + full_url = buildURL(url, params) + if full_url = invalid then return invalid + req = createObject("roUrlTransfer") + req.setUrl(full_url) + req = authorize_request(req) + ' SSL cert serverURL = get_setting("server") if serverURL <> invalid and serverURL.left(8) = "https://" req.setCertificatesFile("common:/certs/ca-bundle.crt") end if - full_url = buildURL(url, params) - req.setUrl(full_url) - req = authorize_request(req) - return req end function @@ -120,18 +124,18 @@ function deleteVoid(req) end function function get_url() - base = get_setting("server") - if base <> invalid - if base.right(1) = "/" - base = base.left(base.len() - 1) - end if + serverURL = get_setting("server") + if serverURL = invalid then return invalid - ' append http:// to the start if not specified - if base.left(7) <> "http://" and base.left(8) <> "https://" - base = "http://" + base - end if + if serverURL.right(1) = "/" + serverURL = serverURL.left(serverURL.len() - 1) end if - return base + + ' append http:// to the start if not specified + if serverURL.left(7) <> "http://" and serverURL.left(8) <> "https://" + serverURL = "http://" + serverURL + end if + return serverURL end function function authorize_request(request)