Skip to content

Commit 9665758

Browse files
committed
refactor: valdiate url before making a request
1 parent 2c33bf8 commit 9665758

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Connection/RESTConnector.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,16 @@ public bool? DisableSslVerification
262262
/// <param name="function">The name of the function.</param>
263263
/// <returns>Returns a RESTConnector object or null on error.</returns>
264264
///
265-
public static RESTConnector GetConnector(Authenticator authenticator, string function)
265+
public static RESTConnector GetConnector(Authenticator authenticator, string function, string url)
266266
{
267+
if (Utility.HasBadFirstOrLastCharacter(url))
268+
{
269+
throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters.");
270+
}
271+
267272
RESTConnector connector = new RESTConnector
268273
{
269-
URL = authenticator.Url + function,
274+
URL = url + function,
270275
Authentication = authenticator
271276
};
272277
return connector;

Connection/WSConnector.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
using System.Security.Authentication;
2626
using IBM.Cloud.SDK.Authentication;
2727
using System.Threading;
28+
using System;
2829
#if !NETFX_CORE
2930
using UnitySDK.WebSocketSharp;
3031
#else
31-
using System;
3232
using System.Threading.Tasks;
3333
using Windows.Networking.Sockets;
3434
using Windows.Security.Credentials;
@@ -328,12 +328,17 @@ public static string FixupURL(string URL)
328328
/// <param name="function">The name of the function to connect.</param>
329329
/// <param name="args">Additional function arguments.</param>
330330
/// <returns>The WSConnector object or null or error.</returns>
331-
public static WSConnector CreateConnector(Authenticator authenticator, string function, string args)
331+
public static WSConnector CreateConnector(Authenticator authenticator, string function, string args, string url)
332332
{
333+
if (Utility.HasBadFirstOrLastCharacter(url))
334+
{
335+
throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters.");
336+
}
337+
333338
WSConnector connector = new WSConnector();
334339
connector.Authentication = authenticator;
335340

336-
connector.URL = FixupURL(authenticator.Url) + function + args;
341+
connector.URL = FixupURL(url) + function + args;
337342

338343
return connector;
339344
}

0 commit comments

Comments
 (0)