File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -273,10 +273,11 @@ pub fn source_browser_handler(req: &mut Request) -> IronResult<Response> {
273
273
} ;
274
274
275
275
let ( file, file_content) = if let Some ( blob) = blob {
276
+ let is_text = blob. mime . starts_with ( "text" ) || blob. mime == "application/json" ;
276
277
// serve the file with DatabaseFileHandler if file isn't text and not empty
277
- if !blob . mime . starts_with ( "text" ) && !blob. is_empty ( ) {
278
+ if !is_text && !blob. is_empty ( ) {
278
279
return Ok ( DbFile ( blob) . serve ( ) ) ;
279
- } else if blob . mime . starts_with ( "text" ) && !blob. is_empty ( ) {
280
+ } else if is_text && !blob. is_empty ( ) {
280
281
let path = blob
281
282
. path
282
283
. rsplit_once ( '/' )
@@ -478,4 +479,29 @@ mod tests {
478
479
Ok ( ( ) )
479
480
} ) ;
480
481
}
482
+
483
+ #[ test]
484
+ fn json_is_served_as_rendered_html ( ) {
485
+ wrapper ( |env| {
486
+ env. fake_release ( )
487
+ . name ( "fake" )
488
+ . version ( "0.1.0" )
489
+ . source_file ( "config.json" , b"{}" )
490
+ . create ( ) ?;
491
+
492
+ let web = env. frontend ( ) ;
493
+
494
+ let response = web. get ( "/crate/fake/0.1.0/source/config.json" ) . send ( ) ?;
495
+ assert ! ( response
496
+ . headers( )
497
+ . get( "content-type" )
498
+ . unwrap( )
499
+ . to_str( )
500
+ . unwrap( )
501
+ . starts_with( "text/html" ) ) ;
502
+ assert ! ( response. text( ) ?. starts_with( r#"<!DOCTYPE html>"# ) ) ;
503
+
504
+ Ok ( ( ) )
505
+ } ) ;
506
+ }
481
507
}
You can’t perform that action at this time.
0 commit comments