Skip to content

ToRespond.WithBody() not handled AContentType correctly #61

@17-year-old

Description

@17-year-old

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions