FluiTec / FluiTec.DatevSharp

DATEV-Library in C#
Other
14 stars 5 forks source link

Validator should check for special chars in text fields #5

Closed ketos closed 4 years ago

ketos commented 4 years ago

I had '\n' chars in some of my 'BookingText' Properties and did not notice. The exported EXTF File was therefore not importable.

I extended the validator with this:

RuleFor(booking => booking.DocumentField1).Must(documentField1 => documentField1 == null || documentField1.IndexOfAny(new[] {'\r', '\n'}) != -1) .WithMessage("DocumentField1 must not contain special characters.");

IInvocation commented 4 years ago

I'm unsure if this is the best solution :/ Wouldnt it be better to automatically replace invalid characters with a simple space? (I guess this would be happening either way in the end...)

Apart from this - i'd have to consider this for every string-field - pretty much a dealbreaker imho.

For the time being - i extended to StringHelper to replace newline-chars with a simple space since this would easily fix things for every string-field.

ketos commented 4 years ago

you're right, this is the easier solution.

Thanks for the fast respond and your efford with this library.

IInvocation commented 4 years ago

Had to update again since i was using string.empty instead of space. Also - i just realized i need to escape quotes which is now done as well. (see a65f972 )