Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360812 - isLike doesn't correctly handle escape character, leading blanks, or empty pattern
Summary: isLike doesn't correctly handle escape character, leading blanks, or empty pa...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P1 normal (vote)
Target Milestone: ---   Edit
Assignee: Huang Ji Yong CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 09:01 EDT by Kathy Carroll CLA
Modified: 2017-02-23 14:14 EST (History)
3 users (show)

See Also:


Attachments
Fix (2.24 KB, patch)
2011-11-20 03:49 EST, Huang Ji Yong CLA
lasher: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kathy Carroll CLA 2011-10-13 09:01:55 EDT
Use eunit framework.  All variations should pass

library tester

	s1 string;
	pattern string;
	escapeStr string;
	actual boolean;
	expected boolean;

	// isLike with escape no match
	function runIsLikeFunction07(){@Test}	
		s1 = "ab%defd";
		pattern = "ab\\%def";
		actual = s1.isLike(pattern);
		expected = false;
		LogResult.assertTrue1( (actual == expected) );
	end

	// isLike with escapeStr no match
	function runIsLikeFunction08(){@Test}	
		s1 = "ab%defd";
		pattern = "ab+%def";
		escapeStr = "+";
		actual = s1.isLike(pattern, escapeStr);
		expected = false;
		LogResult.assertTrue1( (actual == expected) );
	end
	
	// isLike with leading spaces
	function runIsLikeFunction09(){@Test}
		s1 = "  hello";
		pattern = "     hello";
		actual = s1.isLike(pattern);
		expected = false;
		LogResult.assertTrue1((actual == expected) );

	end
	
	// isLike with empty parameter
	function runIsLikeFunction11(){@Test}
		s1 = "ab*def";
		pattern = "";
		actual = s1.isLike(pattern);
		expected = false;
		LogResult.assertTrue1( (actual == expected) );
	end

end
Comment 1 Scott Greer CLA 2011-10-17 10:54:06 EDT
Matt,

Can you comment on this?  

I noticed that the old RT used to trim the pattern, rather than clip it, so I fixed that and now I get the expected results for the 2nd and 3rd tests;  however, the first and last tests still fail but for a different reason.  Neither the old JS RT nor the new Java RT seem to assume an implied end-of-string on the pattern, so in both of these tests, the result is "true" because the resulting regexp patterns are a subset of the strings being considered.  So, we need a ruling on this (preferably resulting in more details in the comments for this function in EString.egl).
Comment 2 Matt Heitz CLA 2011-10-17 11:18:29 EDT
Scott, please ask Brian.  I can't work on EDT anymore.  Have to be on RBD full-time for a while.
Comment 3 Scott Greer CLA 2011-10-17 14:40:01 EDT
Brian,

Since Matt is unavailable, can you make the language ruling required for me to finish fixing this, or name someone who can?
Comment 4 Kathy Carroll CLA 2011-10-18 11:02:17 EDT
matches might have similar issue

	function runMatchesPatternFunction08(){@Test}
		s1 string = "  ab*def";
		pattern string = "ab\\*[abcd][abcde][^a-e]";
		actual string = s1.matchesPattern(pattern);
		expected boolean = false;
		LogResult.assertTrue("matchesPattern with complex pattern and leading spaces", (actual == expected) ); 
	end
	
		function runMatchesPatternFunction11(){@Test}
		s1 string = "ab*def";
		pattern string = "";
		actual string = s1.matchesPattern(pattern);
		expected boolean= false;
		LogResult.assertTrue("matchesPattern with empty parameter", (actual == expected) );
	end
Comment 5 Huang Ji Yong CLA 2011-11-17 22:18:16 EST
Hi Kathy,
I'm not sure if the following variation is correct
1. function runIsLikeFunction08(){@Test} 
s1 = "ab%defd";
pattern = "ab+%def";
escapeStr = "+";

Since "+" is escape character, then the pattern is identical to "ab%def", why the result is false?

2.function runIsLikeFunction11(){@Test} and function runMatchesPatternFunction11(){@Test}
pattern = "";
I think any string should match empty string.

What do you think?
Comment 6 Kathy Carroll CLA 2011-11-18 11:14:59 EST
The first string ends with an extra d which makes the pattern match fail.

s1 = "ab%defd";

Second question, the string includes the pattern but isn't the pattern.
Comment 7 Huang Ji Yong CLA 2011-11-20 03:49:51 EST
Created attachment 207274 [details]
Fix
Comment 8 Huang Ji Yong CLA 2011-11-20 03:50:37 EST
EUnit EString007 all passed
Comment 9 Kathy Carroll CLA 2011-11-28 07:48:54 EST
Verified with 20111127_2101 and closed