Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0EE87D00D for ; Thu, 10 Jan 2013 10:28:58 +0000 (UTC) Received: (qmail 92124 invoked by uid 500); 10 Jan 2013 10:28:57 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 91985 invoked by uid 500); 10 Jan 2013 10:28:56 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 91952 invoked by uid 99); 10 Jan 2013 10:28:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jan 2013 10:28:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jan 2013 10:28:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8D8B2238896F; Thu, 10 Jan 2013 10:28:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1431259 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Date: Thu, 10 Jan 2013 10:28:34 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130110102834.8D8B2238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Thu Jan 10 10:28:33 2013 New Revision: 1431259 URL: http://svn.apache.org/viewvc?rev=1431259&view=rev Log: DERBY-6030: Length of escape string in LIKE ... ESCAPE not properly checked with territory based collation Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?rev=1431259&r1=1431258&r2=1431259&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java Thu Jan 10 10:28:33 2013 @@ -153,7 +153,8 @@ final class WorkHorseForCollatorDatatype CollationElementsInterface escapeCharacter = (CollationElementsInterface) escape; - if (!escapeCharacter.hasSingleCollationElement()) + if (escape.getLength() != 1 || + !escapeCharacter.hasSingleCollationElement()) { throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER, escapeCharacter.toString()); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1431259&r1=1431258&r2=1431259&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Thu Jan 10 10:28:33 2013 @@ -81,6 +81,7 @@ public class CollationTest extends BaseJ /** Test cases to run with Norwegian case-sensitive collation. */ private final static String[] NORWEGIAN_CASE_SENSITIVE = { "testNorwayCollation", + "testLikeEscapeClauseLengthRestriction", }; /** Test cases to run with Polish case-sensitive collation. */ @@ -98,6 +99,9 @@ public class CollationTest extends BaseJ "testSwedishCaseInsensitiveCollation", }; + /** SQL state that signals invalid escape sequence in LIKE expressions. */ + private final static String INVALID_ESCAPE = "22019"; + /** * Test order by with default collation * @@ -2189,4 +2193,49 @@ public void testMissingCollatorSupport() return new HarmonySerialClob( contents ); } + /** + * Regression test case for DERBY-6030. The escape sequence in a LIKE + * expression should consist of a single character and a single collation + * element. Before DERBY-6030, with non-literal escape sequences, Derby + * would only check that the sequence consisted of a single collation + * element, and might incorrectly accept escape sequences with more than + * one character. + */ + public void testLikeEscapeClauseLengthRestriction() throws SQLException { + setAutoCommit(false); + Statement s = createStatement(); + s.execute("create table d6030" + + "(x varchar(10), y varchar(10), z varchar(10))"); + s.execute("insert into d6030 values ('a', 'b', 'c')"); + + PreparedStatement select = prepareStatement( + "select * from d6030 where x like y escape z"); + + PreparedStatement update = prepareStatement("update d6030 set z = ?"); + + // Escape clause 'c' is OK. + JDBC.assertEmpty(select.executeQuery()); + + // Sharp-s is NOT OK, as it has two collation elements. + update.setString(1, "\u00df"); + assertUpdateCount(update, 1); + assertStatementError(INVALID_ESCAPE, select); + + // 'aa' is NOT OK, as it has two characters. This used to succeed with + // Norwegian collation, which treats 'aa' as a single collation + // element. But it should fail since it's two characters. + update.setString(1, "aa"); + assertUpdateCount(update, 1); + assertStatementError(INVALID_ESCAPE, select); + + // Also test the same queries with literals in the escape clause. + // Those queries follow a different code path, and they produced the + // expected results even before the fix. + JDBC.assertEmpty( + s.executeQuery("select * from d6030 where x like y escape 'c'")); + assertStatementError(INVALID_ESCAPE, s, + "select * from d6030 where x like y escape '\u00df'"); + assertStatementError(INVALID_ESCAPE, s, + "select * from d6030 where x like y escape 'aa'"); + } }