Skip to content

Commit

Permalink
Merge pull request #15 from Qnerd/master
Browse files Browse the repository at this point in the history
SubMatches are added on every call
  • Loading branch information
arimus committed Nov 14, 2013
2 parents 7c0d1b1 + bd5672a commit 646d824
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/sf/jmimemagic/MagicMatch.java
Expand Up @@ -400,9 +400,11 @@ protected Object clone()
clone.setOffset(offset);

// these properties should only be String types, so we shouldn't have to clone them
HashMap m = new HashMap();
m.putAll(properties);
clone.setProperties(m);
if(properties!= null) {
HashMap m = new HashMap();
m.putAll(properties);
clone.setProperties(m);
}

Iterator i = subMatches.iterator();
ArrayList a = new ArrayList();
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/sf/jmimemagic/MagicMatcher.java
Expand Up @@ -239,7 +239,12 @@ public MagicMatch test(File f, boolean onlyMimeMatch)

if (testInternal(buf)) {
// set the top level match to this one
match = getMatch();
try {
match = getMatch() != null ? (MagicMatch) getMatch()
.clone() : null;
} catch (CloneNotSupportedException e) {
// noop
}

log.debug("test(File): testing matched '" + description + "'");

Expand Down Expand Up @@ -343,7 +348,12 @@ public MagicMatch test(byte[] data, boolean onlyMimeMatch)

if (testInternal(buf)) {
// set the top level match to this one
match = getMatch();
try {
match = getMatch() != null ? (MagicMatch) getMatch()
.clone() : null;
} catch (CloneNotSupportedException e) {
// noop
}

log.debug("test(byte[]): testing matched '" + description + "'");

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/net/sf/jmimemagic/MagicTest.java
Expand Up @@ -375,4 +375,23 @@ public void testZip(){
}

}

public void testSubMatches(){
System.out.print("\ntesting Submatches...");
try {
MagicMatch match = Magic.getMagicMatch(new File(gifFile), true, false);
Assert.assertEquals(3, match.getSubMatches().size());
match = Magic.getMagicMatch(new File(gifFile), true, false);
Assert.assertEquals(3, match.getSubMatches().size());
System.out.print("ok");
} catch (Exception e) {
e.printStackTrace();
fail("exception in testSubMatches(). message: " + e);
} catch (Error e) {
e.printStackTrace();
fail("error in testSubMatches(). message: " + e.getMessage());
}

}

}

0 comments on commit 646d824

Please sign in to comment.