#1 2016-02-05 14:04:25

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

SOAPUI 5 double quotes Content-Type

Hi @ab,

   I am testing with SOAPUI 5.2.1 (the latest) and when upload a file SOAPUI send a double quotes in Content-Type and MultiPartFormDataDecode fail. According to this thread https://github.com/vkholodkov/nginx-upl … /issues/50:

piersh commented on 5 Nov 2014
RFC2616 clearly states the quotes are valid. here are the relevant lines:

Content-Type = "Content-Type" ":" media-type
media-type = type "/" subtype *( ";" parameter )
parameter = attribute "=" value
value = token | quoted-string <-- the value can be quoted
quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
qdtext = <any TEXT except <">>
similarly for the quotes in FILENAME_STRING and FIELDNAME_STRING, except the quotes around those are optional.

any standards-compliant client code (concrete or otherwise) will break it.

i can give you concrete code if you really want, but it will be a bash script piping a POST through netcat. i can't give you my actual code (because lawyers).

I made a small modification to SynCommons.MultiPartFormDataDecode to compliant with the above:

function MultiPartFormDataDecode(const MimeType,Body: RawUTF8;
  var MultiPart: TMultiPartDynArray): boolean;
var boundary,endBoundary,tmp: RawUTF8;
    i,j: integer;
    P: PUTF8Char;
    part: TMultiPart;
begin
  result := false;
  i := PosEx('boundary=',MimeType);
  if i=0 then
    exit;
  tmp := trim(copy(MimeType,i+9,200));
  if (tmp[1]<>'"') then
    boundary := '--'+tmp
  else
    boundary := '--'+copy(tmp,2,length(tmp)-2); // copy removing double quotes
  endBoundary := boundary+'--'+#13#10;
  boundary := boundary+#13#10;
  i := PosEx(boundary,Body);
  if i<>0 then
  repeat
    inc(i,length(boundary));
    if i=length(body) then
      exit; // reached the end
    P := PUTF8Char(Pointer(Body))+i-1;
    Finalize(part);
    repeat
      if IdemPCharAndGetNextItem(P,
         'CONTENT-DISPOSITION: FORM-DATA; NAME="',part.Name,'"') then
        IdemPCharAndGetNextItem(P,'; FILENAME="',part.FileName,'"') else
      if IdemPCharAndGetNextItem(P,'CONTENT-TYPE: ',part.ContentType) or
         IdemPCharAndGetNextItem(P,'CONTENT-TRANSFER-ENCODING: ',part.Encoding) then;
      GetNextLineBegin(P,P);
      if P=nil then
        exit;
    until PWord(P)^=13+10 shl 8;
    i := P-PUTF8Char(Pointer(Body))+3; // i = just after header
    j := PosEx(boundary,Body,i);
    if j=0 then begin
     j := PosEx(endboundary,Body,i); // try last boundary
     if j=0 then
      exit;
    end;
    part.Content := copy(Body,i,j-i-2); // -2 to ignore latest #13#10
    if (part.ContentType='') or (PosEx('-8',part.ContentType)>0) then begin
      part.ContentType := TEXT_CONTENT_TYPE;
      {$ifdef HASCODEPAGE}
      SetCodePage(part.Content,CP_UTF8,false); // ensure raw field value is UTF-8
      {$endif}
    end else
    if IdemPropNameU(part.Encoding,'base64') then
      part.Content := Base64ToBin(part.Content);
    // note: "quoted-printable" not yet handled here
    SetLength(MultiPart,length(MultiPart)+1);
    MultiPart[high(MultiPart)] := part;
    result := true;
    i := j;
  until false;
end;

If you are agree can you apply or improve this ?

Thanks.

Esteban


Esteban

Offline

#2 2016-02-08 15:45:04

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: SOAPUI 5 double quotes Content-Type

@ab, do you think about this ?

Thanks


Esteban

Offline

#3 2016-02-08 16:15:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: SOAPUI 5 double quotes Content-Type

Should be included with http://synopse.info/fossil/info/9ce1705181

Thanks for the input.
Sorry for the late answer.

Offline

#4 2016-02-10 10:27:49

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: SOAPUI 5 double quotes Content-Type

Thanks !!!


Esteban

Offline

Board footer

Powered by FluxBB