Fix bug #19311: notice and report unterminated comments in text catalogs
git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1dafbf63c9
commit
1de3bfa617
@ -84,6 +84,8 @@ public class CatalogException extends Exception {
|
||||
public static final int UNPARSEABLE = 6;
|
||||
/** XML but parse failed */
|
||||
public static final int PARSE_FAILED = 7;
|
||||
/** Text catalog ended in mid-comment */
|
||||
public static final int UNENDED_COMMENT = 8;
|
||||
|
||||
/**
|
||||
* The embedded exception if tunnelling, or null.
|
||||
|
||||
@ -113,6 +113,7 @@ public class TR9401CatalogReader extends TextCatalogReader {
|
||||
|
||||
Vector unknownEntry = null;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
String token = nextToken();
|
||||
|
||||
@ -161,8 +162,16 @@ public class TR9401CatalogReader extends TextCatalogReader {
|
||||
} else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
|
||||
catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token);
|
||||
unknownEntry = null;
|
||||
} else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) {
|
||||
catalog.getCatalogManager().debug.message(1, cex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CatalogException cex2) {
|
||||
if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) {
|
||||
catalog.getCatalogManager().debug.message(1, cex2.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,6 +156,7 @@ public class TextCatalogReader implements CatalogReader {
|
||||
|
||||
Vector unknownEntry = null;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
String token = nextToken();
|
||||
|
||||
@ -200,9 +201,16 @@ public class TextCatalogReader implements CatalogReader {
|
||||
} else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
|
||||
catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token);
|
||||
unknownEntry = null;
|
||||
} else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) {
|
||||
catalog.getCatalogManager().debug.message(1, cex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CatalogException cex2) {
|
||||
if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) {
|
||||
catalog.getCatalogManager().debug.message(1, cex2.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,10 +234,13 @@ public class TextCatalogReader implements CatalogReader {
|
||||
/**
|
||||
* Return the next token in the catalog file.
|
||||
*
|
||||
* <p>FYI: This code does not throw any sort of exception for
|
||||
* a file that contains an n
|
||||
*
|
||||
* @return The Catalog file token from the input stream.
|
||||
* @throws IOException If an error occurs reading from the stream.
|
||||
*/
|
||||
protected String nextToken() throws IOException {
|
||||
protected String nextToken() throws IOException, CatalogException {
|
||||
String token = "";
|
||||
int ch, nextch;
|
||||
|
||||
@ -258,11 +269,16 @@ public class TextCatalogReader implements CatalogReader {
|
||||
// we've found a comment, skip it...
|
||||
ch = ' ';
|
||||
nextch = nextChar();
|
||||
while (ch != '-' || nextch != '-') {
|
||||
while ((ch != '-' || nextch != '-') && nextch > 0) {
|
||||
ch = nextch;
|
||||
nextch = nextChar();
|
||||
}
|
||||
|
||||
if (nextch < 0) {
|
||||
throw new CatalogException(CatalogException.UNENDED_COMMENT,
|
||||
"Unterminated comment in catalog file; EOF treated as end-of-comment.");
|
||||
}
|
||||
|
||||
// Ok, we've found the end of the comment,
|
||||
// loop back to the top and start again...
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user