Skip to content

Commit 94512d8

Browse files
committed
Ajustes gerais
Correção da validação de data hora!
1 parent 0ecb4de commit 94512d8

18 files changed

+44
-27
lines changed

src/sanitializators/Sanitizer.Custom.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ constructor TSanitizerCustom.Create(const AExecute: TDataValidatorCustomSanitize
5757

5858
function TSanitizerCustom.Sanitize: TValue;
5959
var
60-
LValue: TValue;
60+
LValue: string;
6161
begin
62+
LValue := GetValueAsString;
63+
6264
if Assigned(FExecute) then
6365
begin
64-
LValue := FExecute(GetValueAsString);
66+
LValue := FExecute(LValue);
6567
SetValueAdapter(LValue);
6668
end;
6769

src/sanitializators/Sanitizer.OnlyNumbers.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ constructor TSanitizerOnlyNumbers.Create;
5656

5757
function TSanitizerOnlyNumbers.Sanitize: TValue;
5858
var
59-
LValue: TValue;
59+
LValue: string;
6060
begin
61-
LValue := TRegEx.Replace(GetValueAsString, '\D', '');
61+
LValue := GetValueAsString;
62+
63+
LValue := TRegEx.Replace(LValue, '\D', '');
6264

6365
SetValueAdapter(LValue);
6466

src/sanitializators/Sanitizer.RemoveAccents.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function TSanitizerRemoveAccents.Sanitize: TValue;
5959
var
6060
LValue: string;
6161
begin
62-
LValue := string(ASCIIString(GetValueAsString));
62+
LValue := GetValueAsString;
63+
64+
LValue := string(ASCIIString(LValue));
6365

6466
SetValueAdapter(LValue);
6567

src/sanitializators/Sanitizer.Replace.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ function TSanitizerReplace.Sanitize: TValue;
6262
var
6363
LValue: string;
6464
begin
65-
LValue := GetValueAsString.Replace(FOldValue, FNewValue);
65+
LValue := GetValueAsString;
66+
67+
LValue := StringReplace(LValue, FOldValue, FNewValue, [rfReplaceAll]);
6668

6769
SetValueAdapter(LValue);
6870

src/sanitializators/Sanitizer.ToDate.pas

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,23 @@ constructor TSanitizerToDate.Create(const AJSONISO8601ReturnUTC: Boolean);
5959
function TSanitizerToDate.Sanitize: TValue;
6060
var
6161
LValue: string;
62+
LValueSanitize: string;
6263
R: Boolean;
6364
LDate: TDateTime;
6465
begin
6566
LValue := Trim(GetValueAsString);
66-
LValue := LValue.Replace('\', '');
67+
LValueSanitize := StringReplace(LValue, '\', '', [rfReplaceAll]);
6768

68-
R := TryStrToDate(LValue, LDate);
69+
R := TryStrToDate(LValueSanitize, LDate);
6970

7071
if not R then
71-
R := TryISO8601ToDate(LValue, LDate, FJSONISO8601ReturnUTC);
72+
R := TryISO8601ToDate(LValueSanitize, LDate, FJSONISO8601ReturnUTC);
7273

7374
if R then
74-
SetValueAdapter(TValue.From<TDate>(LDate));
75+
if LValue <> LValueSanitize then
76+
SetValueAdapter(LValueSanitize)
77+
else
78+
SetValueAdapter(TValue.From<TDate>(LDate));
7579

7680
Result := FValue;
7781
end;

src/sanitializators/Sanitizer.ToDateTime.pas

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,23 @@ constructor TSanitizerToDateTime.Create(const AJSONISO8601ReturnUTC: Boolean);
5959
function TSanitizerToDateTime.Sanitize: TValue;
6060
var
6161
LValue: string;
62+
LValueSanitize: string;
6263
R: Boolean;
6364
LDateTime: TDateTime;
6465
begin
6566
LValue := Trim(GetValueAsString);
66-
LValue := LValue.Replace('\', '');
67+
LValueSanitize := StringReplace(LValue, '\', '', [rfReplaceAll]);
6768

68-
R := TryStrToDateTime(LValue, LDateTime);
69+
R := TryStrToDateTime(LValueSanitize, LDateTime);
6970

7071
if not R then
71-
R := TryISO8601ToDate(LValue, LDateTime, FJSONISO8601ReturnUTC);
72+
R := TryISO8601ToDate(LValueSanitize, LDateTime, FJSONISO8601ReturnUTC);
7273

7374
if R then
74-
SetValueAdapter(TValue.From<TDateTime>(LDateTime));
75+
if LValue <> LValueSanitize then
76+
SetValueAdapter(LValueSanitize)
77+
else
78+
SetValueAdapter(TValue.From<TDate>(LDateTime));
7579

7680
Result := FValue;
7781
end;

src/sanitializators/Sanitizer.ToMD5.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ constructor TSanitizerToMD5.Create;
5656

5757
function TSanitizerToMD5.Sanitize: TValue;
5858
var
59-
LValue: TValue;
59+
LValue: string;
6060
begin
61-
LValue := THashMD5.GetHashString(GetValueAsString);
61+
LValue := GetValueAsString;
62+
LValue := THashMD5.GetHashString(LValue);
6263

6364
SetValueAdapter(LValue);
6465

src/validators/Validator.IsDate.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function TValidatorIsDate.Check: IDataValidatorResult;
6969

7070
if not Trim(LValue).IsEmpty then
7171
begin
72-
LValue := LValue.Replace('\', '');
72+
LValue := StringReplace(LValue, '\', '', [rfReplaceAll]);
7373

7474
R := TryStrToDate(LValue, LDate);
7575

src/validators/Validator.IsDateBetween.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function TValidatorIsDateBetween.Check: IDataValidatorResult;
7373

7474
if not Trim(LValue).IsEmpty then
7575
begin
76-
LValue := LValue.Replace('\', '');
76+
LValue := StringReplace(LValue, '\', '', [rfReplaceAll]);
7777

7878
R := TryStrToDate(LValue, LDate);
7979

src/validators/Validator.IsDateEquals.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function TValidatorIsDateEquals.Check: IDataValidatorResult;
7171

7272
if not Trim(LValue).IsEmpty then
7373
begin
74-
LValue := LValue.Replace('\', '');
74+
LValue := StringReplace(LValue, '\', '', [rfReplaceAll]);
7575

7676
R := TryStrToDate(LValue, LDate);
7777

0 commit comments

Comments
 (0)