You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2011/10/10 10:14:51 UTC
svn commit: r1180823 - in /wicket/trunk/wicket-util/src:
main/java/org/apache/wicket/util/io/FullyBufferedReader.java
test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java
Author: mgrigorov
Date: Mon Oct 10 08:14:50 2011
New Revision: 1180823
URL: http://svn.apache.org/viewvc?rev=1180823&view=rev
Log:
WICKET-4117 Improve markup parsing in order to generate a meaningful message when a not balanced quote is found.
Modified:
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/FullyBufferedReader.java
wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java
Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/FullyBufferedReader.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/FullyBufferedReader.java?rev=1180823&r1=1180822&r2=1180823&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/FullyBufferedReader.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/FullyBufferedReader.java Mon Oct 10 08:14:50 2011
@@ -274,9 +274,17 @@ public final class FullyBufferedReader
}
// I've found character but I'm inside quotes
if (currentChar == ch && quotationChar != 0)
+ {
return findOutOfQuotes(ch, closeBracketIndex + 1, quotationChar);
+ }
}
}
+ else if (quotationChar != 0)
+ {
+ // quotes not balanced!
+ throw new ParseException("Opening/closing quote not found for quote at " + "(line " +
+ getLineNumber() + ", column " + getColumnNumber() + ")", startPos);
+ }
return closeBracketIndex;
}
Modified: wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java?rev=1180823&r1=1180822&r2=1180823&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java (original)
+++ wicket/trunk/wicket-util/src/test/java/org/apache/wicket/util/io/FullyBufferedReaderTest.java Mon Oct 10 08:14:50 2011
@@ -18,16 +18,23 @@ package org.apache.wicket.util.io;
import java.text.ParseException;
-import junit.framework.TestCase;
-
+import org.junit.Assert;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
-
-public class FullyBufferedReaderTest extends TestCase
+/**
+ * Tests for {@link FullyBufferedReader}
+ */
+public class FullyBufferedReaderTest extends Assert
{
+ /**
+ *
+ * @throws ParseException
+ */
@Test
- public void testNestedQuotes() throws ParseException
+ public void nestedQuotes() throws ParseException
{
// testTag is <a href='b \'" > a' theAtr="at'r'\"r">
String testTag = "<a href='b \\'\" > a' theAtr=\"at'r'\\\"r\">";
@@ -42,8 +49,12 @@ public class FullyBufferedReaderTest ext
assertEquals(testTag.length(), position + 1);
}
+ /**
+ *
+ * @throws ParseException
+ */
@Test
- public void testQuotedEsclamationQuotationMark() throws ParseException
+ public void quotedEsclamationQuotationMark() throws ParseException
{
// testTag is <a href='b " >!! a<??!!' theAtr=">">
String testTag = "<a href='b \" >!! a<??!!' theAtr=\">\">";
@@ -57,4 +68,86 @@ public class FullyBufferedReaderTest ext
// close bracket must be at the end of the string
assertEquals(testTag.length(), position + 1);
}
+
+ /**
+ * A rule for expecting ParseExceptions
+ */
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-4117
+ *
+ * Test exception when we forgot to close quote
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void missingClosingQuote() throws ParseException
+ {
+ thrown.expect(ParseException.class);
+ thrown.expectMessage("Opening/closing quote not found for quote at (line 1, column 9)");
+
+ String testTag = "<a href='blabla>";
+ FullyBufferedReader fullyBufferedReader = new FullyBufferedReader(testTag);
+
+ fullyBufferedReader.findOutOfQuotes('>', 0);
+ }
+
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-4117
+ *
+ * Test exception when we forgot to close quote
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void missingOpeningQuote() throws ParseException
+ {
+ thrown.expect(ParseException.class);
+ thrown.expectMessage("Opening/closing quote not found for quote at (line 1, column 15)");
+
+ String testTag = "<a href=blabla'>";
+ FullyBufferedReader fullyBufferedReader = new FullyBufferedReader(testTag);
+
+ fullyBufferedReader.findOutOfQuotes('>', 0);
+ }
+
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-4117
+ *
+ * Test exception when we forgot to close quote
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void missingClosingDoubleQuote() throws ParseException
+ {
+ thrown.expect(ParseException.class);
+ thrown.expectMessage("Opening/closing quote not found for quote at (line 1, column 9)");
+
+ String testTag = "<a href=\"blabla>";
+ FullyBufferedReader fullyBufferedReader = new FullyBufferedReader(testTag);
+
+ fullyBufferedReader.findOutOfQuotes('>', 0);
+ }
+
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-4117
+ *
+ * Test exception when we forgot to close quote
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void missingOpeningDoubleQuote() throws ParseException
+ {
+ thrown.expect(ParseException.class);
+ thrown.expectMessage("Opening/closing quote not found for quote at (line 1, column 15)");
+
+ String testTag = "<a href=blabla\">";
+ FullyBufferedReader fullyBufferedReader = new FullyBufferedReader(testTag);
+
+ fullyBufferedReader.findOutOfQuotes('>', 0);
+ }
}
\ No newline at end of file