coliver 2003/12/29 13:26:05
Modified: src/java/org/apache/cocoon/generation JXTemplateGenerator.java Log: Handle unterminated ${ and #{ Revision Changes Path 1.25 +36 -2 cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java Index: JXTemplateGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- JXTemplateGenerator.java 28 Dec 2003 22:54:07 -0000 1.24 +++ JXTemplateGenerator.java 29 Dec 2003 21:26:05 -0000 1.25 @@ -907,9 +907,9 @@ if (inStr == null) return null; StringReader in = new StringReader(inStr.trim()); int ch; - StringBuffer expr = new StringBuffer(); boolean xpath = false; boolean inExpr = false; + StringBuffer expr = new StringBuffer(); while ((ch = in.read()) != -1) { char c = (char)ch; if (inExpr) { @@ -940,6 +940,16 @@ return new Expression(inStr, null); } } + if (inExpr) { + // unclosed #{} or ${} + String msg; + if (xpath) { + msg = "Unterminated #{"; + } else { + msg = "Unterminated ${"; + } + throw new Exception(msg); + } } catch (IOException ignored) { ignored.printStackTrace(); } @@ -1134,13 +1144,17 @@ int ch; boolean inExpr = false; boolean xpath = false; + int line = location.getLineNumber(); + int column = location.getColumnNumber(); try { top: while ((ch = in.read()) != -1) { + column++; char c = (char)ch; processChar: while (true) { if (inExpr) { if (c == '\\') { ch = in.read(); + if (ch == -1) { buf.append('\\'); } else { @@ -1210,6 +1224,16 @@ // won't happen ignored.printStackTrace(); } + if (inExpr) { + // unclosed #{} or ${} + String str; + if (xpath) { + str = "#{"; + } else { + str = "${"; + } + buf.insert(0, str); + } if (buf.length() > 0) { char[] charArray = new char[buf.length()]; @@ -1436,6 +1460,16 @@ } } catch (IOException ignored) { ignored.printStackTrace(); + } + if (inExpr) { + // unclosed #{} or ${} + String msg; + if (xpath) { + msg = "Unterminated #{"; + } else { + msg = "Unterminated ${"; + } + throw new SAXParseException(msg, location, null); } if (buf.length() > 0) { if (substEvents.size() == 0) {