cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2284 Expression likeIgnoreCase can't handle unicode chars in in-memory evaluation
Date Thu, 27 Apr 2017 08:01:47 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master a8960c559 -> 38a368f70


CAY-2284 Expression likeIgnoreCase can't handle unicode chars in in-memory evaluation


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/38a368f7
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/38a368f7
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/38a368f7

Branch: refs/heads/master
Commit: 38a368f709b0879b117bc674760c34e8d956cbfe
Parents: a8960c5
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Apr 27 10:16:30 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Apr 27 10:16:30 2017 +0300

----------------------------------------------------------------------
 .../main/java/org/apache/cayenne/util/Util.java |  2 +-
 .../apache/cayenne/exp/parser/ASTEqualTest.java | 21 ++++++++++++++++++++
 .../exp/parser/ASTLikeIgnoreCaseTest.java       | 21 ++++++++++++++++++++
 .../apache/cayenne/exp/parser/ASTLikeTest.java  | 21 ++++++++++++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  2 ++
 5 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/38a368f7/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java b/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java
index ba30b97..7dfd57e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java
@@ -485,7 +485,7 @@ public class Util {
 	public static Pattern sqlPatternToPattern(String pattern, boolean ignoreCase) {
 		String preprocessed = RegexUtil.sqlPatternToRegex(pattern);
 
-		int flag = (ignoreCase) ? Pattern.CASE_INSENSITIVE : 0;
+		int flag = (ignoreCase) ? Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE : 0;
 		return Pattern.compile(preprocessed, flag);
 	}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38a368f7/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
index 5579dd5..207680a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
@@ -98,4 +98,25 @@ public class ASTEqualTest {
 		p.setEstimatedPrice(bd4);
 		assertFalse(equalTo.match(p));
 	}
+
+	@Test
+	public void testEvaluateUnicodeChars() {
+		ASTEqual equalToFull = new ASTEqual(new ASTObjPath("artistName"), "àбçğþ");
+		ASTEqual equalToSimple = new ASTEqual(new ASTObjPath("artistName"), "àğç");
+
+		Artist noMatch = new Artist();
+		noMatch.setArtistName("agc");
+		assertFalse(equalToSimple.match(noMatch));
+		assertFalse(equalToFull.match(noMatch));
+
+		Artist matchSimple = new Artist();
+		matchSimple.setArtistName("àğç");
+		assertTrue(equalToSimple.match(matchSimple));
+		assertFalse(equalToFull.match(matchSimple));
+
+		Artist matchFull = new Artist();
+		matchFull.setArtistName("àбçğþ");
+		assertFalse(equalToSimple.match(matchFull));
+		assertTrue(equalToFull.match(matchFull));
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38a368f7/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
index 55946cf..d0f566f 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
@@ -85,6 +85,27 @@ public class ASTLikeIgnoreCaseTest {
 		assertTrue("Failed: " + like, notLike.match(match2));
 	}
 
+	@Test
+	public void testEvaluateUnicode() {
+		Expression like = new ASTLikeIgnoreCase(new ASTObjPath("artistName"), "ÀБĞÞ%");
+		Expression notLike = new ASTNotLikeIgnoreCase(new ASTObjPath("artistName"), "ÀБĞÞ%");
+
+		Artist noMatch1 = new Artist();
+		noMatch1.setArtistName("àbğþ");
+		assertFalse(like.match(noMatch1));
+		assertTrue(notLike.match(noMatch1));
+
+		Artist match1 = new Artist();
+		match1.setArtistName("àбğþd");
+		assertTrue("Failed: " + like, like.match(match1));
+		assertFalse("Failed: " + notLike, notLike.match(match1));
+
+		Artist match2 = new Artist();
+		match2.setArtistName("àБğÞ");
+		assertTrue("Failed: " + like, like.match(match2));
+		assertFalse("Failed: " + notLike, notLike.match(match2));
+	}
+
 	private Painting createPainting(String name) {
 		Painting p = new Painting();
 		p.setPaintingTitle(name);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38a368f7/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
index 48d6890..f908d53 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
@@ -92,4 +92,25 @@ public class ASTLikeTest {
 		assertTrue("Failed: " + like, like.match(match));
 	}
 
+	@Test
+	public void testEvaluateUnicode() {
+		Expression like = new ASTLike(new ASTObjPath("artistName"), "àбğþ%");
+		Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "àбğþ%");
+
+		Artist noMatch1 = new Artist();
+		noMatch1.setArtistName("àbğþd");
+		assertFalse(like.match(noMatch1));
+		assertTrue(notLike.match(noMatch1));
+
+		Artist match1 = new Artist();
+		match1.setArtistName("àбğþ");
+		assertTrue("Failed: " + like, like.match(match1));
+		assertFalse("Failed: " + notLike, notLike.match(match1));
+
+		Artist match2 = new Artist();
+		match2.setArtistName("àбğþa");
+		assertTrue("Failed: " + like, like.match(match2));
+		assertFalse("Failed: " + notLike, notLike.match(match2));
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38a368f7/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 85c8871..674903a 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -55,6 +55,8 @@ CAY-2275 Documentation: tutorial is out of sync with 4.0.M5 version
 CAY-2276 PrePersist listener registered as PostPersist in LifecycleCallbackRegistry.addListener(Class<?>,
LifecycleListener)
 CAY-2279 cdbimport: skip PK comparison for VIEWs
 CAY-2281 ObjEntity attribute overrides are never deleted
+CAY-2284 Expression likeIgnoreCase can't handle unicode chars in in-memory evaluation
+
 ----------------------------------
 Release: 4.0.M5
 Date: March 6, 2017


Mime
View raw message