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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Arciiix
Copy link
Contributor

@Arciiix Arciiix commented Jul 4, 2024

Fixes #247 , more info there.

Can you please review my code for now so that I can make some appropriate changes?

Cheers

Copy link
Collaborator

@SebastianStehle SebastianStehle left a comment

Choose a reason for hiding this comment

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

The main thing is that you have forgotten the server side validation and I am not so happy with client side validation yet. See comments for more infos. Continue with the good work :)

@@ -42,7 +42,6 @@ public sealed partial class SmtpIntegration : IIntegration

public static readonly IntegrationProperty FromEmailProperty = new IntegrationProperty("fromEmail", PropertyType.Text)
{
Pattern = Patterns.Email,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you put this property at the end, just like in the other property?. My brain is annoying sometimes ;)

if (property.format && property.format !== "None") {
const format = FORMAT_REGEXPS.get(property.format);


Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove double line.



if (format) {
propertyType = propertyType.matches(format, texts.validation.formatFn);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup already provides validation method for email and url. Just use that. There is also emailI18n and perhaps url18n for localized methods in the code base.

@@ -441,6 +441,7 @@ export const EN = {
minItemsFn: (p: { label?: string; min: number }) => `${p.label} must have at least ${p.min || 0} items.`,
minLengthFn: (p: { label?: string; min: number }) => `${p.label} must have at least ${p.min} characters.`,
moreThanFn: (p: { label?: string; more: number }) => `${p.label} must be greater than ${p.more || 0}.`,
formatFn: (p: { label?: string }) => `${p.label} is not in a valid format for this type of field.`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have introduced the format property to provide better validation messages. Otherwise we could just use "pattern", which has a very generic method.

@@ -39,6 +39,8 @@ public sealed record IntegrationProperty(string Name, PropertyType Type)

public string? Pattern { get; init; }

public PropertyFormat Format { get; init; } = PropertyFormat.None;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Validation is missing in the TryGetString method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing URL validation that can lead to internal error
2 participants