Skip to content

Commit 69a82cf

Browse files
committed
fix: Correção de parse de www-form-url-encoded para detectar o separador do body diferente do header
1 parent a9ddbd9 commit 69a82cf

2 files changed

Lines changed: 49 additions & 13 deletions

File tree

src/base/RALParams.pas

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Unit that contains everything related to Params from either the query request
1+
/// Unit that contains everything related to Params from either the query request
22
/// or response.
33
unit RALParams;
44

@@ -101,7 +101,8 @@ TRALParams = class
101101
function Encrypt(AStream: TStream): TStream;
102102

103103
/// Results either = or : if found on the input text.
104-
function FindNameSeparator(const ASource: StringRAL): StringRAL;
104+
function FindHeaderNameSeparator(const ASource: StringRAL): StringRAL;
105+
function FindBodyNameSeparator(const ASource: StringRAL): StringRAL;
105106
function GetBody: TList;
106107
function GetParam(AIndex: IntegerRAL; AKind: TRALParamKind): TRALParam; overload;
107108
function GetParam(AIndex: IntegerRAL): TRALParam; overload;
@@ -136,6 +137,8 @@ TRALParams = class
136137
procedure AppendParams(ASource: TStringList; AKind: TRALParamKind); overload;
137138
/// Used to append a list of params (ASource) to the current params list.
138139
procedure AppendParams(ASource: TStrings; AKind: TRALParamKind); overload;
140+
/// Used to append a list of params (ASource) from the body to the current params list.
141+
procedure AppendBodyParams(ASource: TStrings; AKind: TRALParamKind);
139142
/// Used to append a list of params in a string to the current params list.
140143
procedure AppendParamsListText(ASource: StringRAL; AKind: TRALParamKind;
141144
ANameSeparator: StringRAL = '');
@@ -626,7 +629,7 @@ procedure TRALParams.AppendParams(ASource: TStrings; AKind: TRALParamKind);
626629
vSeparator: StringRAL;
627630
begin
628631
if ASource.Count > 0 then
629-
vSeparator := FindNameSeparator(ASource.Strings[0]);
632+
vSeparator := FindHeaderNameSeparator(ASource.Strings[0]);
630633

631634
for vInt := 0 to Pred(ASource.Count) do
632635
AppendParamLine(ASource.Strings[vInt], vSeparator, AKind);
@@ -646,7 +649,7 @@ procedure TRALParams.AppendParamsListText(ASource: StringRAL; AKind: TRALParamKi
646649
{$ENDIF}
647650

648651
if (ASource <> '') and (ANameSeparator = '') then
649-
ANameSeparator := FindNameSeparator(ASource);
652+
ANameSeparator := FindHeaderNameSeparator(ASource);
650653

651654
vLine := '';
652655
for vInt := POSINISTR to RALHighStr(ASource) do
@@ -1015,7 +1018,7 @@ procedure TRALParams.DecodeFields(const ASource: StringRAL; AKind: TRALParamKind
10151018
begin
10161019
vStringList := URLEncodedToList(ASource);
10171020
try
1018-
AppendParams(vStringList, AKind);
1021+
AppendBodyParams(vStringList, AKind);
10191022
finally
10201023
FreeAndNil(vStringList);
10211024
end;
@@ -1161,7 +1164,25 @@ function TRALParams.NextParamStr: StringRAL;
11611164
Result := 'ral_param' + IntToStr(FNextParam);
11621165
end;
11631166

1164-
function TRALParams.FindNameSeparator(const ASource: StringRAL): StringRAL;
1167+
function TRALParams.FindBodyNameSeparator(const ASource: StringRAL): StringRAL;
1168+
var
1169+
vPos, vMin: IntegerRAL;
1170+
begin
1171+
begin
1172+
vMin := Length(ASource);
1173+
vPos := Pos('=', ASource);
1174+
if (vPos > 0) and (vPos <= vMin) then
1175+
Result := '='
1176+
else
1177+
begin
1178+
vPos := Pos(StringRAL(': '), ASource);
1179+
if (vPos > 0) and (vPos <= vMin) then
1180+
Result := ': ';
1181+
end;
1182+
end;
1183+
end;
1184+
1185+
function TRALParams.FindHeaderNameSeparator(const ASource: StringRAL): StringRAL;
11651186
var
11661187
vPos, vMin: IntegerRAL;
11671188
Engine: StringRAL;
@@ -1187,6 +1208,18 @@ function TRALParams.FindNameSeparator(const ASource: StringRAL): StringRAL;
11871208
end;
11881209
end;
11891210

1211+
procedure TRALParams.AppendBodyParams(ASource: TStrings; AKind: TRALParamKind);
1212+
var
1213+
vInt: Integer;
1214+
vSeparator: StringRAL;
1215+
begin
1216+
if ASource.Count > 0 then
1217+
vSeparator := FindBodyNameSeparator(ASource.Strings[0]);
1218+
1219+
for vInt := 0 to Pred(ASource.Count) do
1220+
AppendParamLine(ASource.Strings[vInt], vSeparator, AKind);
1221+
end;
1222+
11901223
procedure TRALParams.AppendParamLine(const ALine, ANameSeparator: StringRAL;
11911224
AKind: TRALParamKind);
11921225
var

src/utils/RALStream.pas

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,16 @@ function StreamToString(AStream: TStream): StringRAL;
157157
end
158158
else
159159
begin
160-
vStream := TStringStream.Create(EmptyStr);
161-
try
162-
vStream.CopyFrom(AStream, AStream.Size);
163-
Result := TStringStream(vStream).DataString;
164-
finally
165-
FreeAndNil(vStream);
166-
end;
160+
vStream := TRALStringStream.Create(AStream);
161+
Result := TRALStringStream(vStream).DataString;
162+
163+
// vStream := TStringStream.Create(EmptyStr);
164+
// try
165+
// vStream.CopyFrom(AStream, AStream.Size);
166+
// Result := TStringStream(vStream).DataString;
167+
// finally
168+
// FreeAndNil(vStream);
169+
// end;
167170
end;
168171
end;
169172

0 commit comments

Comments
 (0)