Delphi-WebMocks icon indicating copy to clipboard operation
Delphi-WebMocks copied to clipboard

ToRespond.WithBody() not handled AContentType correctly

Open 17-year-old opened this issue 5 months ago • 0 comments

If there are characters in contentstring that are not in the default character set,an error will occur. I think the problem is here:

function TWebMockResponseContentString.GetContentStream: TStream;
begin
  Result := TStringStream.Create(ContentString);
end;

Which uses the default Encoding to encode ContentString. It should be something like this:

function TWebMockResponseContentString.GetContentStream: TStream;
var
  LCharset: string;
begin
  LCharset := GetContentCharset;
  if (LCharset <> '') and (string.CompareText(LCharset, 'utf-8') <> 0) then // do not translate
    Result := TStringStream.Create(ContentString, TEncoding.GetEncoding(LCharset), True)
  else
    Result := TStringStream.Create(ContentString, TEncoding.UTF8, False);
end;

17-year-old avatar Jul 04 '25 06:07 17-year-old