Delphi-WebMocks
Delphi-WebMocks copied to clipboard
ToRespond.WithBody() not handled AContentType correctly
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;