Fossil SCM
Use the same definition of BINARY in multiple places of fossil. Reported by sky5walk.
Commit
b51ba29365b93b3fa13f7fc05034ec6a8dc38b22
Parent
690824e991b8416…
1 file changed
+3
-14
+3
-14
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -35,15 +35,10 @@ | ||
| 35 | 35 | const char *mimetype_from_content(Blob *pBlob){ |
| 36 | 36 | int i; |
| 37 | 37 | int n; |
| 38 | 38 | const unsigned char *x; |
| 39 | 39 | |
| 40 | - static const char isBinary[256] = { | |
| 41 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, | |
| 42 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 | |
| 43 | - }; | |
| 44 | - | |
| 45 | 40 | /* A table of mimetypes based on file content prefixes |
| 46 | 41 | */ |
| 47 | 42 | static const struct { |
| 48 | 43 | const char *zPrefix; /* The file prefix */ |
| 49 | 44 | int size; /* Length of the prefix */ |
| @@ -54,21 +49,15 @@ | ||
| 54 | 49 | { "\211PNG\r\n\032\n", 8, "image/png" }, |
| 55 | 50 | { "\377\332\377", 3, "image/jpeg" }, |
| 56 | 51 | { "\377\330\377", 3, "image/jpeg" }, |
| 57 | 52 | }; |
| 58 | 53 | |
| 54 | + if( !looks_like_binary(pBlob) ) { | |
| 55 | + return 0; /* Plain text */ | |
| 56 | + } | |
| 59 | 57 | x = (const unsigned char*)blob_buffer(pBlob); |
| 60 | 58 | n = blob_size(pBlob); |
| 61 | - for(i=0; i<n; i++){ | |
| 62 | - unsigned char c = x[i]; | |
| 63 | - if( isBinary[c] ){ | |
| 64 | - break; | |
| 65 | - } | |
| 66 | - } | |
| 67 | - if( i>=n ){ | |
| 68 | - return 0; /* Plain text */ | |
| 69 | - } | |
| 70 | 59 | for(i=0; i<ArraySize(aMime); i++){ |
| 71 | 60 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 72 | 61 | return aMime[i].zMimetype; |
| 73 | 62 | } |
| 74 | 63 | } |
| 75 | 64 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -35,15 +35,10 @@ | |
| 35 | const char *mimetype_from_content(Blob *pBlob){ |
| 36 | int i; |
| 37 | int n; |
| 38 | const unsigned char *x; |
| 39 | |
| 40 | static const char isBinary[256] = { |
| 41 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, |
| 42 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 |
| 43 | }; |
| 44 | |
| 45 | /* A table of mimetypes based on file content prefixes |
| 46 | */ |
| 47 | static const struct { |
| 48 | const char *zPrefix; /* The file prefix */ |
| 49 | int size; /* Length of the prefix */ |
| @@ -54,21 +49,15 @@ | |
| 54 | { "\211PNG\r\n\032\n", 8, "image/png" }, |
| 55 | { "\377\332\377", 3, "image/jpeg" }, |
| 56 | { "\377\330\377", 3, "image/jpeg" }, |
| 57 | }; |
| 58 | |
| 59 | x = (const unsigned char*)blob_buffer(pBlob); |
| 60 | n = blob_size(pBlob); |
| 61 | for(i=0; i<n; i++){ |
| 62 | unsigned char c = x[i]; |
| 63 | if( isBinary[c] ){ |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | if( i>=n ){ |
| 68 | return 0; /* Plain text */ |
| 69 | } |
| 70 | for(i=0; i<ArraySize(aMime); i++){ |
| 71 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 72 | return aMime[i].zMimetype; |
| 73 | } |
| 74 | } |
| 75 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -35,15 +35,10 @@ | |
| 35 | const char *mimetype_from_content(Blob *pBlob){ |
| 36 | int i; |
| 37 | int n; |
| 38 | const unsigned char *x; |
| 39 | |
| 40 | /* A table of mimetypes based on file content prefixes |
| 41 | */ |
| 42 | static const struct { |
| 43 | const char *zPrefix; /* The file prefix */ |
| 44 | int size; /* Length of the prefix */ |
| @@ -54,21 +49,15 @@ | |
| 49 | { "\211PNG\r\n\032\n", 8, "image/png" }, |
| 50 | { "\377\332\377", 3, "image/jpeg" }, |
| 51 | { "\377\330\377", 3, "image/jpeg" }, |
| 52 | }; |
| 53 | |
| 54 | if( !looks_like_binary(pBlob) ) { |
| 55 | return 0; /* Plain text */ |
| 56 | } |
| 57 | x = (const unsigned char*)blob_buffer(pBlob); |
| 58 | n = blob_size(pBlob); |
| 59 | for(i=0; i<ArraySize(aMime); i++){ |
| 60 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 61 | return aMime[i].zMimetype; |
| 62 | } |
| 63 | } |
| 64 |