Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PropertyFormat to avoid validation errors that can lead to internal exceptions #248

Merged
merged 12 commits into from
Aug 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Notifo.Domain.Integrations.Resources;
using Notifo.Infrastructure.Validation;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.RegularExpressions;
using Notifo.Domain.Integrations.Resources;
using Notifo.Infrastructure.Validation;

#pragma warning disable SA1313 // Parameter names should begin with lower-case letter

Expand Down Expand Up @@ -185,8 +185,10 @@ private bool TryGetString(string? input, [MaybeNullWhen(true)] out string error,

break;
case PropertyFormat.HttpUrl:
// We only allow http and https to enable the usage of URL field for HttpClient requests.
if (!Uri.TryCreate(input, UriKind.Absolute, out var uri) || !((string[])["http", "https"]).Contains(uri.Scheme, StringComparer.OrdinalIgnoreCase))
// We only allow "http" and "https" schemas to enable the usage of URL field for HttpClient requests.
if (!Uri.TryCreate(input, UriKind.Absolute, out var uri)
|| (!string.Equals(uri.Scheme, "http", StringComparison.OrdinalIgnoreCase) && !string.Equals(uri.Scheme, "https", StringComparison.OrdinalIgnoreCase))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just create a static readonly field with HttpSchemes, would have been shorter ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I do it in another pull request? I see you already merged this one :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, plz :)

)
{
error = Texts.IntegrationPropertyFormatHttpUrl;
return false;
Expand Down