Consultor Eletrônico



Kbase P100703: MATCHES returns FALSE when strings match
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   18/12/2009
Status: Verified

SYMPTOM(s):

MATCHES returns FALSE when strings match

MATCHES pattern string contains tilde or backslash

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x
All Supported Operating Systems

CAUSE:

The tilde and backslash are escape characters on UNIX. (On Windows, only the tilde is an escape character.)

Because it supports wildcards, MATCHES has to take into account escape characters in the pattern string for those cases where a literal match on the wildcard character is required (ie: the string to match to should be an actual asterisk "*", not any group of characters).
Thus any literal match on an escape character will also fail unless the escape character itself is escaped.

FIX:

Parse the pattern string to ensure all escape characters are properly escaped, so they will be treated literally during the processing of the MATCHES operator.

Sample code:

FUNCTION matchesPattern RETURNS CHARACTER
(INPUT cString AS CHARACTER):
DEFINE VARIABLE iEntries AS INTEGER NO-UNDO.

cString = REPLACE(cString , "~~" , "~~~~").
IF OPSYS = "UNIX" THEN cString = REPLACE(cString , "~\" , "~~~\").

RETURN cString.
END.
MESSAGE "x~\x" MATCHES matchesPattern("x~\x") VIEW-AS ALERT-BOX.