Bug Reports
wwUtils.prg::URLEncode
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
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 ---
Thanks, Rick! If there is an experimental zip available for download, we'll gladly use it.