Page 1 of 1

Error in EscapeQuotes function

Posted: 08.04.2006, 00:42
by btrewern
Does anybody else think this function looks wrong

Code: Select all

function EscapeQuotes(const Value: string): string;
var
  I: Integer;
  PrevChar, PrevPrevChar: string;
begin
  Result := '';
  PrevChar := ' ';
  PrevPrevChar := ' ';
  for I := 1 to Length(Value) do
  begin
    Result := Result + Value[I];
    if (Value[I] = '''') and ((PrevChar <> '\') or
       (PrevChar = '\') or (PrevPrevChar = '\')) then
      Result := Result + '''';
    PrevPrevChar := PrevChar;
    PrevChar := Value[I];
  end;
end;
It's from ZDbcPostgreSQLUtils.pas. I assume that the writer meant the middle if statement to read

Code: Select all

    if (Value[I] = '''') and ((PrevChar <> '\') or
       ((PrevChar = '\') and (PrevPrevChar = '\'))) then
but I still don't think that would work with strings like \\\'
Anybody have any ideas?

Regards,

Ben.

Posted: 08.04.2006, 20:08
by mdaems
Hi Ben,

A far as I can see you're right. Can you fix it? If you can change it in the latest SVN version and you submit a diff to this forum (or to firmos by pm) there's a good chance it wil be introduced in the codebase (unless the change is very big).

Concerning the \\\' case, as I don't know what the functionis used for, I can't predict if that situation is likely to occur. I that kind of string is passed to the function it will certainly give a bad result.

Mark