Bug Reports
wwUtils.prg::URLEncode
Gravatar is a globally recognized avatar based on your email address. wwUtils.prg::URLEncode
  Michael J. Babcock
  All
  Oct 26, 2026 @ 10:37am

When a null gets passed, the len(tcValue) errors. Suggest this simple line at the top of the routine (or some derivative thereof):

tcValue = nvl(tcValue,'')

Thanks, --Michael

FUNCTION URLEncode
*******************
***  Function: Encodes a string in URL encoded format
***            for use on URL strings or when passing a
***            POST buffer to wwIPStuff::HTTPGetEx
***      Pass: tcValue  -   String to encode
***    Return: URLEncoded string or ""
********************************************************
LPARAMETER tcValue
LOCAL lcResult, lcChar, lnSize, lnX

* mjb 2026-10-26 handle so no error due to NULL passed in
tcValue = NVL(tcValue,'')

*** Large Buffers use the wwIPStuff function 
*** for quicker response
if  LEN(tcValue) > 512
   lnSize=LEN(tcValue)
   tcValue=PADR(tcValue,lnSize * 3)

   PUBLIC __VFPUrlEncodeAPI
   IF !__VFPUrlEncodeAPI
	   DECLARE INTEGER VFPURLEncode ;
	      IN WWIPSTUFF ;
	      STRING @cText,;
	      INTEGER cInputTextSize
	      __VFPUrlEncodeAPI = .T.
   ENDIF	
   
   lnSize=VFPUrlEncode(@tcValue,lnSize)
   
   IF lnSize > 0
      RETURN SUBSTR(TRIM(tcValue),1,lnSize)
   ENDIF
   RETURN ""
ENDIF   
   
*** Do it in VFP Code
lcResult=""

FOR lnX=1 to len(tcValue)
   lcChar = SUBSTR(tcValue,lnX,1)
   DO CASE
   CASE ATC(lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~") > 0
      lcResult=lcResult + lcChar
   CASE lcChar=" "
      lcResult = lcResult + "%20"
   OTHERWISE
	   *** Convert others to Hex equivalents
	   lcResult = lcResult + "%" + RIGHT(transform(ASC(lcChar),"@0"),2)
   ENDCASE
ENDFOR && lnX=1 to len(tcValue)

RETURN lcResult

Gravatar is a globally recognized avatar based on your email address. re: wwUtils.prg::URLEncode
  Rick Strahl
  Michael J. Babcock
  Oct 26, 2026 @ 11:15am

Good suggestion. Added.

That said - just about none of the utility string functions check for nulls... so there's that. 😄

Many check for EMPTY() or VARTYPE() that latter of which will catch null, but the former will not. It's an abomination in FoxPro that EMPTY(.null.) returns .f..

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwUtils.prg::URLEncode
  Michael J. Babcock
  Rick Strahl
  Oct 26, 2026 @ 01:41pm

Thanks, Rick! If there is an experimental zip available for download, we'll gladly use it.

Gravatar is a globally recognized avatar based on your email address. re: wwUtils.prg::URLEncode
  Rick Strahl
  Michael J. Babcock
  Oct 27, 2026 @ 06:57am

I'm shooting for a full update in the next week or so...

+++ Rick ---

© 1996-2026