Skip to content

Commit

Permalink
Merge pull request JodaOrg#333 from emopers/HasMoreElements_362_363
Browse files Browse the repository at this point in the history
ZoneInfoCompiler$Zone does not check validity of input file
  • Loading branch information
jodastephen committed Dec 7, 2015
2 parents 73fd550 + 76fa437 commit 9ced54c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ public void parseDataFile(BufferedReader in, boolean backward) throws IOExceptio
rs.addRule(r);
}
} else if (token.equalsIgnoreCase("Zone")) {
if (st.countTokens() < 4) {
throw new IllegalArgumentException("Attempting to create a Zone from an incomplete tokenizer");
}
zone = new Zone(st);
} else if (token.equalsIgnoreCase("Link")) {
String real = st.nextToken();
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/joda/time/tz/TestCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public static TestSuite suite() {
"Rule US 1918 1919 - Mar lastSun 2:00 1:00 D\n" +
"Rule \n" ; // this line is intentionally incomplete

static final String BROKEN_TIMEZONE_FILE_2 =
"# Incomplete Zone for building America/Los_Angeles time zone.\n" +
"\n" +
"Rule CA 1948 only - Mar 14 2:00 1:00 D\n" +
"Rule CA 1949 only - Jan 1 2:00 0 S\n" +
"\n" +
"Zone "; // this line is intentionally left incomplete

private DateTimeZone originalDateTimeZone = null;

public TestCompiler(String name) {
Expand Down Expand Up @@ -136,6 +144,17 @@ public void testCompileOnBrokenTimeZoneFile() throws Exception {
assertEquals("Attempting to create a Rule from an incomplete tokenizer", iae.getMessage());
}
}
public void testCompileOnBrokenTimeZoneFile_2() throws Exception {
try {
Provider provider = compileAndLoad(BROKEN_TIMEZONE_FILE_2);
fail();
} catch(NoSuchElementException nsee) {
// This thrown from the Zone constructor
fail("NoSuchElementException was thrown; broken timezone file?");
} catch(IllegalArgumentException iae) {
assertEquals("Attempting to create a Zone from an incomplete tokenizer", iae.getMessage());
}
}

private Provider compileAndLoad(String data) throws Exception {
File tempDir = createDataFile(data);
Expand Down

0 comments on commit 9ced54c

Please sign in to comment.