From 0159a99b17d70f9bfee9c74368ef7c8a433c4320 Mon Sep 17 00:00:00 2001 From: coffeegreg <86416144+coffeegreg@users.noreply.github.com> Date: Sat, 16 Dec 2023 20:02:58 +0100 Subject: [PATCH] Issue #12 fix Issue #12 fix. --- src/common.pas | 18 +++++++++++++++++- src/httpserver.pas | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/common.pas b/src/common.pas index 6b904dd..1cb0063 100644 --- a/src/common.pas +++ b/src/common.pas @@ -16,7 +16,7 @@ interface const APP_NAME = 'YTuner'; - APP_VERSION = '1.1.0'; + APP_VERSION = '1.1.1'; APP_COPYRIGHT = 'Copyright (c) 2023 Greg P. (https://github.com/coffeegreg)'; INI_VERSION = '1.1.0'; @@ -104,6 +104,7 @@ function RemoveEscChars(LInputStr: RawByteString): RawByteString; function HaveCommonElements(AStr: string; AStrArray: array of string): boolean; function ContainsIn(AStr: string; AStrArray: array of string): boolean; function StripChars(AInputString: string):string; +function URLEncode(const AStr: String): AnsiString; implementation @@ -235,6 +236,21 @@ function StripChars(AInputString: string):string; Result:=DelSpace1(StringsReplace(AInputString,STRIP_CHARS,(DupeString(' ,',Length(STRIP_CHARS)-1)+' ').Split([',']),[rfReplaceAll]).Trim); end; +function URLEncode(const AStr: String): AnsiString; +var + LAnsiChar: AnsiChar; +begin + Result:=''; + for LAnsiChar in AStr do + begin + if ((Ord(LAnsiChar)<65) or (Ord(LAnsiChar)>90)) + and ((Ord(LAnsiChar)<97) or (Ord(LAnsiChar)>122)) then + Result:=Result+'%'+IntToHex(Ord(LAnsiChar),2) + else + Result:=Result+LAnsiChar; + end; +end; + end. diff --git a/src/httpserver.pas b/src/httpserver.pas index 1065796..4a40f71 100644 --- a/src/httpserver.pas +++ b/src/httpserver.pas @@ -284,7 +284,7 @@ procedure GetMyStationsCategories(AReq: TRequest; ARes: TResponse); begin for i:=LFirstElement to LLastElement do with MyStations[i] do - LMyPage.Add(SetVTunerDirectory(MSCategory,PATH_ROOT+'/'+PATH_MY_STATIONS+'/'+MSCategory,Length(MSStations))); + LMyPage.Add(SetVTunerDirectory(MSCategory,PATH_ROOT+'/'+PATH_MY_STATIONS+'/'+URLEncode(MSCategory),Length(MSStations))); SendPageResponse(HTTP_CODE_OK,ctXML,ARes,LMyPage); end else @@ -552,7 +552,7 @@ procedure GetRadioBrowserCategoryType(AReq: TRequest; ARes: TResponse); LMyPage.TotalItemsCount:=LRBCategories.Count; for i:=LFirstElement to LLastElement do with TRBCategory(LRBCategories.Objects[i]) do - LMyPage.Add(SetVTunerDirectory(RBCName,PATH_ROOT+'/'+PATH_RADIOBROWSER+'/'+PATH_RADIOBROWSER_CATEGORIES[LCategoryIdx]+'/'+RBCName,RBCMaxCount)); + LMyPage.Add(SetVTunerDirectory(RBCName,PATH_ROOT+'/'+PATH_RADIOBROWSER+'/'+PATH_RADIOBROWSER_CATEGORIES[LCategoryIdx]+'/'+URLEncode(RBCName),RBCMaxCount)); SendPageResponse(HTTP_CODE_OK,ctXML,ARes,LMyPage); finally LMyPage.Free;