@@ -105,12 +105,18 @@ const FILE_SIGNATURES: [[&[u8]; 2]; 18] = [
105
105
[ b"....moov" , b"video/quicktime" ] ,
106
106
[ b"\x1A \x45 \xDF \xA3 " , b"video/webm" ] ,
107
107
] ;
108
+ // All known non-"text/..." plaintext media types
108
109
const PLAINTEXT_MEDIA_TYPES : & [ & str ] = & [
109
- "application/javascript" ,
110
- "application/json" ,
111
- "image/svg+xml" ,
110
+ "application/json" , // .json
111
+ "application/ld+json" , // .jsonld
112
+ "application/x-sh" , // .sh
113
+ "application/xhtml+xml" , // .xhtml
114
+ "application/xml" , // .xml
115
+ "application/vnd.mozilla.xul+xml" , // .xul
116
+ "image/svg+xml" , // .svg
112
117
] ;
113
118
119
+ // TODO: split it into three separate functions [create_from_data(), create_from_url(), create() -- create is likely not public]
114
120
pub fn create_monolithic_document (
115
121
source : String ,
116
122
options : & Options ,
@@ -137,7 +143,9 @@ pub fn create_monolithic_document(
137
143
"-" => {
138
144
// Read from pipe (stdin)
139
145
use_stdin = true ;
140
- // Set default target URL to an empty data URL; the user can set it via --base-url
146
+
147
+ // Set default target URL to an empty data URL
148
+ // (the user can change it by using the custom base URL option)
141
149
Url :: parse ( "data:text/html," ) . unwrap ( )
142
150
}
143
151
target => match Url :: parse ( target) {
@@ -266,7 +274,7 @@ pub fn create_monolithic_document(
266
274
}
267
275
}
268
276
269
- // Use custom base URL if specified, read and use what's in the DOM otherwise
277
+ // Use custom base URL if specified; read and use what's in the DOM otherwise
270
278
let custom_base_url: String = options. base_url . clone ( ) . unwrap_or ( "" . to_string ( ) ) ;
271
279
if custom_base_url. is_empty ( ) {
272
280
// No custom base URL is specified
@@ -389,8 +397,9 @@ pub fn detect_media_type_by_file_name(filename: &str) -> String {
389
397
"htm" | "html" => "text/html" ,
390
398
"ico" => "image/x-icon" ,
391
399
"jpeg" | "jpg" => "image/jpeg" ,
392
- "js" => "application /javascript" ,
400
+ "js" => "text /javascript" ,
393
401
"json" => "application/json" ,
402
+ "jsonld" => "application/ld+json" ,
394
403
"mp3" => "audio/mpeg" ,
395
404
"mp4" | "m4v" => "video/mp4" ,
396
405
"ogg" => "audio/ogg" ,
@@ -405,12 +414,12 @@ pub fn detect_media_type_by_file_name(filename: &str) -> String {
405
414
"webp" => "image/webp" ,
406
415
"woff" => "font/woff" ,
407
416
"woff2" => "font/woff2" ,
417
+ "xhtml" => "application/xhtml+xml" ,
408
418
"xml" => "text/xml" ,
409
419
& _ => "" ,
410
420
} ,
411
421
None => "" ,
412
422
} ;
413
-
414
423
mime. to_string ( )
415
424
}
416
425
@@ -511,9 +520,11 @@ pub fn retrieve_asset(
511
520
let ( media_type, charset, data) = parse_data_url ( url) ;
512
521
Ok ( ( data, url. clone ( ) , media_type, charset) )
513
522
} else if url. scheme ( ) == "file" {
523
+ let cache_key: String = clean_url ( url. clone ( ) ) . as_str ( ) . to_string ( ) ;
524
+
514
525
// Check if parent_url is also a file: URL (if not, then we don't embed the asset)
515
526
if parent_url. scheme ( ) != "file" {
516
- print_error_message ( & format ! ( "{} (security error)" , & url ) , options) ;
527
+ print_error_message ( & format ! ( "{} (security error)" , & cache_key ) , options) ;
517
528
518
529
// Provoke error
519
530
client. get ( "" ) . send ( ) ?;
@@ -523,12 +534,12 @@ pub fn retrieve_asset(
523
534
let path: & Path = path_buf. as_path ( ) ;
524
535
if path. exists ( ) {
525
536
if path. is_dir ( ) {
526
- print_error_message ( & format ! ( "{} (is a directory)" , & url ) , options) ;
537
+ print_error_message ( & format ! ( "{} (is a directory)" , & cache_key ) , options) ;
527
538
528
539
// Provoke error
529
540
Err ( client. get ( "" ) . send ( ) . unwrap_err ( ) )
530
541
} else {
531
- print_info_message ( & format ! ( "{}" , & url ) , options) ;
542
+ print_info_message ( & cache_key . to_string ( ) , options) ;
532
543
533
544
let file_blob: Vec < u8 > = fs:: read ( path) . expect ( "unable to read file" ) ;
534
545
0 commit comments