Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread Ampersand in the DataSet parameter
Wed, Jan 4 2017 10:33 AMPermanent Link

Trinione

Hi all:
How can a DataSet parameter with an ampersand be sent to the server?

Example: Searching for a CompanyName = 'A & B Limited%'

The ampersand in the URL sends the wrong query.

Example: http://localhost:8090/databases?method=rows&database=THEAPP&dataset=dsCompanySearchByName&companyName=%27A%20&%20B%25%27
Wed, Jan 4 2017 10:46 AMPermanent Link

Matthew Jones

Trinione wrote:

> The ampersand in the URL sends the wrong query.

Interesting that the rest is encoded - you'd have to look at the full path of execution to see where it is not happening. In the meantime, you can easily fix it by replacing it with the appropriate % combination.

--

Matthew Jones
Wed, Jan 4 2017 10:56 AMPermanent Link

Trinione


Nope. I tried that already. I have replaced with '%26', however that does not run the query in the Dataset properly.

I suspect it is seeing it now the Parameter as 'A %26 B%'
Wed, Jan 4 2017 2:37 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< How can a DataSet parameter with an ampersand be sent to the server? >>

This is a bug.  The hot fix is this:

In the WebHTTP unit, replace this method:

procedure TServerRequest.Execute;
var
  I: Integer;
  TempURL: String;
begin
  try
     TempURL:=encodeURI(FURL);
     if (FParams.Count > 0) then
        begin
        TempURL:=TempURL+'?'+encodeURIComponent(FParams[0]);
        for I:=1 to FParams.Count-1 do
           TempURL:=TempURL+'&'+encodeURIComponent(FParams[I]);
        end;
     {$IFNDEF DESIGN}
     FHttpRequest.open(MethodName,TempURL,True,FUserName,FPassword);
     for I:=0 to FRequestHeaders.Count-1 do
        begin
        if (FRequestHeaders.Names[I] <> '') then
           FHttpRequest.setRequestHeader(Trim(FRequestHeaders.Names[I]),
                                         Trim(FRequestHeaders.ValueFromIndex[I]));
        end;
     FHttpRequest.timeout:=FTimeout;
     FHttpRequest.send(FRequestContent.Text);
     {$ENDIF}
  except
     on E: Exception do
        raise Exception.Create(Translate('ERR_HTTP_REQUEST',[FURL,E.Message]));
  end;
end;

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jan 4 2017 5:10 PMPermanent Link

Trinione

Tim Young [Elevate Software] wrote:

<< This is a bug.  The hot fix is this: >>


Thank you Tim.

Question: Would this fix be in the 2.06 Build?
Mon, Jan 9 2017 9:18 AMPermanent Link

Trinione

Tim:
This does not work.

On reopening EWB the line 'TempURL:=encodeUTL(FURL);' produces the following errors/messages in the Output window.

[Error] WebHTTP.wbs (252,15): There is no function or procedure declaration that matches the encodeURI(FURL) reference

[Error] WebHTTP.wbs (255,30): There is no function or procedure declaration that matches the encodeURIComponent(FParams.Strings[0]) reference

[Error] WebHTTP.wbs (255,30): Expected String but instead found encodeURIComponent(FParams.Strings[0])

[Error] WebHTTP.wbs (257,33): There is no function or procedure declaration that matches the encodeURIComponent(FParams.Strings[I]) reference

[Error] WebHTTP.wbs (257,33): Expected String but instead found encodeURIComponent(FParams.Strings[I])

[Error] WebData.wbs (14,15): Cannot compile the referenced unit WebHTTP

[Error] WebForms.wbs (14,15): Referenced unit compilation failed, compilation aborted

[Error] Component Library (3,10): Referenced unit compilation failed, compilation aborted




Tim Young [Elevate Software] wrote:

<< How can a DataSet parameter with an ampersand be sent to the server? >>

This is a bug.  The hot fix is this:

In the WebHTTP unit, replace this method:

procedure TServerRequest.Execute;
var
  I: Integer;
  TempURL: String;
begin
  try
     TempURL:=encodeURI(FURL);
     if (FParams.Count > 0) then
        begin
        TempURL:=TempURL+'?'+encodeURIComponent(FParams[0]);
        for I:=1 to FParams.Count-1 do
           TempURL:=TempURL+'&'+encodeURIComponent(FParams[I]);
        end;
     {$IFNDEF DESIGN}
     FHttpRequest.open(MethodName,TempURL,True,FUserName,FPassword);
     for I:=0 to FRequestHeaders.Count-1 do
        begin
        if (FRequestHeaders.Names[I] <> '') then
           FHttpRequest.setRequestHeader(Trim(FRequestHeaders.Names[I]),
                                         Trim(FRequestHeaders.ValueFromIndex[I]));
        end;
     FHttpRequest.timeout:=FTimeout;
     FHttpRequest.send(FRequestContent.Text);
     {$ENDIF}
  except
     on E: Exception do
        raise Exception.Create(Translate('ERR_HTTP_REQUEST',[FURL,E.Message]));
  end;
end;

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 9 2017 9:30 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/9/2017 9:18 AM, Trinione wrote:
> Tim:
> This does not work.
> On reopening EWB the line 'TempURL:=encodeUTL(FURL);' produces the following errors/messages in the Output window.
> [Error] WebHTTP.wbs (252,15): There is no function or procedure declaration that matches the encodeURI(FURL) reference

The error is due to the uses and ifdefs:

encodeURI is defined in WedDOM but WebHTTP only includes WebDOM at
non-design time ( uses WebCore, {$IFNDEF DESIGN}, WebDOM;{$ELSE};{$ENDIF})


Tim can do a clean version but this quick hack should make it work

procedure TServerRequest.Execute;
var
   I: Integer;
   TempURL: String;
begin
   try
     {$IFNDEF DESIGN}
      TempURL:=encodeURI(FURL);
      if (FParams.Count > 0) then
         begin
         TempURL:=TempURL+'?'+encodeURIComponent(FParams[0]);
         for I:=1 to FParams.Count-1 do
            TempURL:=TempURL+'&'+encodeURIComponent(FParams[I]);
         end;
        {$ELSE}
   TempURL:=FURL;
      if (FParams.Count > 0) then
         begin
         TempURL:=TempURL+'?'+FParams[0];
         for I:=1 to FParams.Count-1 do
            TempURL:=TempURL+'&'+FParams[I];
         end;
   {$ENDIF}
      {$IFNDEF DESIGN}

FHttpRequest.open(MethodName,encodeURI(TempURL),True,FUserName,FPassword);
      for I:=0 to FRequestHeaders.Count-1 do
         begin
         if (FRequestHeaders.Names[I] <> '') then
            FHttpRequest.setRequestHeader(Trim(FRequestHeaders.Names[I]),

Trim(FRequestHeaders.ValueFromIndex[I]));
         end;
      FHttpRequest.timeout:=FTimeout;
      FHttpRequest.send(FRequestContent.Text);
      {$ENDIF}
   except
      on E: Exception do
         raise
Exception.Create(Translate('ERR_HTTP_REQUEST',[FURL,E.Message]));
   end;
end;


Raul
Mon, Jan 9 2017 4:09 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

This is the 2.06 beta candidate version:

procedure TServerRequest.Execute;
{$IFNDEF DESIGN}
var
  I: Integer;
  TempURL: String;
{$ENDIF}
begin
  {$IFNDEF DESIGN}
  try
     TempURL:=encodeURI(FURL);
     if (FParams.Count > 0) then
        begin
        TempURL:=TempURL+'?'+encodeURIComponent(FParams[0]);
        for I:=1 to FParams.Count-1 do
           TempURL:=TempURL+'&'+encodeURIComponent(FParams[I]);
        end;
     FHttpRequest.open(MethodName,TempURL,True,FUserName,FPassword);
     for I:=0 to FRequestHeaders.Count-1 do
        begin
        if (FRequestHeaders.Names[I] <> '') then
           FHttpRequest.setRequestHeader(Trim(FRequestHeaders.Names[I]),
                                         Trim(FRequestHeaders.ValueFromIndex[I]));
        end;
     FHttpRequest.timeout:=FTimeout;
     FHttpRequest.send(FRequestContent.Text);
  except
     on E: Exception do
        raise Exception.Create(Translate('ERR_HTTP_REQUEST',[FURL,E.Message]));
  end;
  {$ENDIF}
end;

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 9 2017 4:10 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< Would this fix be in the 2.06 Build? >>

All hot fixes are always rolled into the latest minor release or build when it's released.

Tim Young
Elevate Software
www.elevatesoft.com
Image