mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-17 19:37:37 +08:00
fix bug
This commit is contained in:
parent
bb89901961
commit
cc6a3d4964
@ -394,6 +394,9 @@ public enum FileMagicNumber {
|
|||||||
WOFF("font/woff", "woff") {
|
WOFF("font/woff", "woff") {
|
||||||
@Override
|
@Override
|
||||||
public boolean match(final byte[] bytes) {
|
public boolean match(final byte[] bytes) {
|
||||||
|
if(bytes.length < 8){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77)
|
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77)
|
||||||
&& Objects.equals(bytes[1], (byte) 0x4f)
|
&& Objects.equals(bytes[1], (byte) 0x4f)
|
||||||
&& Objects.equals(bytes[2], (byte) 0x46)
|
&& Objects.equals(bytes[2], (byte) 0x46)
|
||||||
@ -410,8 +413,7 @@ public enum FileMagicNumber {
|
|||||||
&& Objects.equals(bytes[5], (byte) 0x72)
|
&& Objects.equals(bytes[5], (byte) 0x72)
|
||||||
&& Objects.equals(bytes[6], (byte) 0x75)
|
&& Objects.equals(bytes[6], (byte) 0x75)
|
||||||
&& Objects.equals(bytes[7], (byte) 0x65);
|
&& Objects.equals(bytes[7], (byte) 0x65);
|
||||||
return bytes.length > 7
|
return flag1 && (flag2 || flag3 || flag4);
|
||||||
&& (flag1 && (flag2 || flag3 || flag4));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -420,6 +422,9 @@ public enum FileMagicNumber {
|
|||||||
WOFF2("font/woff2", "woff2") {
|
WOFF2("font/woff2", "woff2") {
|
||||||
@Override
|
@Override
|
||||||
public boolean match(final byte[] bytes) {
|
public boolean match(final byte[] bytes) {
|
||||||
|
if(bytes.length < 8){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77)
|
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77)
|
||||||
&& Objects.equals(bytes[1], (byte) 0x4f)
|
&& Objects.equals(bytes[1], (byte) 0x4f)
|
||||||
&& Objects.equals(bytes[2], (byte) 0x46)
|
&& Objects.equals(bytes[2], (byte) 0x46)
|
||||||
@ -436,8 +441,7 @@ public enum FileMagicNumber {
|
|||||||
&& Objects.equals(bytes[5], (byte) 0x72)
|
&& Objects.equals(bytes[5], (byte) 0x72)
|
||||||
&& Objects.equals(bytes[6], (byte) 0x75)
|
&& Objects.equals(bytes[6], (byte) 0x75)
|
||||||
&& Objects.equals(bytes[7], (byte) 0x65);
|
&& Objects.equals(bytes[7], (byte) 0x65);
|
||||||
return bytes.length > 7
|
return flag1 && (flag2 || flag3 || flag4);
|
||||||
&& (flag1 && (flag2 || flag3 || flag4));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +90,7 @@ public class FileTypeUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void issueI6MACITest() {
|
public void issueI6MACITest() {
|
||||||
final File file = FileUtil.file("text.txt");
|
final File file = FileUtil.file("1.txt");
|
||||||
final String type = FileTypeUtil.getType(file);
|
final String type = FileTypeUtil.getType(file);
|
||||||
Assert.assertEquals("txt", type);
|
Assert.assertEquals("txt", type);
|
||||||
}
|
}
|
||||||
|
1
hutool-core/src/test/resources/1.txt
Normal file
1
hutool-core/src/test/resources/1.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
Loading…
Reference in New Issue
Block a user