Commit f7a9ebf 1 parent a18e395 commit f7a9ebf Copy full SHA for f7a9ebf
File tree 3 files changed +20
-3
lines changed
3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 1
1
use petgraph:: prelude:: * ;
2
+ use std:: cmp:: min;
2
3
use std:: iter:: zip;
3
4
4
5
fn from_u8_singlerule ( bytes : & [ u8 ] , rule : & super :: MagicRule ) -> bool {
5
6
// Check if we're even in bounds
6
7
let bound_min = rule. start_off as usize ;
7
- let bound_max = rule. start_off as usize + rule. val . len ( ) + rule. region_len as usize ;
8
-
9
- if bound_max > bytes. len ( ) {
8
+ if bound_min > bytes. len ( ) {
10
9
return false ;
11
10
}
11
+ let bound_max = rule. start_off as usize + rule. val . len ( ) + rule. region_len as usize ;
12
+ let bound_max = min ( bound_max, bytes. len ( ) ) ;
13
+
12
14
let testarea = & bytes[ bound_min..bound_max] ;
13
15
14
16
testarea. windows ( rule. val . len ( ) ) . any ( |window| {
Original file line number Diff line number Diff line change @@ -83,6 +83,14 @@ mod from_u8 {
83
83
}
84
84
85
85
/// Text tests
86
+ #[ test]
87
+ fn text_html ( ) {
88
+ assert_eq ! (
89
+ tree_magic:: from_u8( include_bytes!( "text/html" ) ) ,
90
+ convmime!( "text/html" )
91
+ ) ;
92
+ }
93
+
86
94
#[ test]
87
95
fn text_plain ( ) {
88
96
assert_eq ! (
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <title>Test</title>
5
+ </head>
6
+ <body></body>
7
+ </html>
You can’t perform that action at this time.
0 commit comments