Fossil SCM
Tweak [1f20d61a07] to avoid broken UTF-8 sequences at the end of truncated comments.
Commit
f661b8de491e40daa44c37eba66f02cca0acfa0cc2a683bc577071412699b1ea
Parent
df668553c0f0b47…
2 files changed
+12
-1
+5
-8
+12
-1
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -744,15 +744,26 @@ | ||
| 744 | 744 | void blob_rewind(Blob *p){ |
| 745 | 745 | p->iCursor = 0; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /* |
| 749 | -** Truncate a blob back to zero length | |
| 749 | +** Truncate a blob to the specified length in bytes. | |
| 750 | 750 | */ |
| 751 | 751 | void blob_truncate(Blob *p, int sz){ |
| 752 | 752 | if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz; |
| 753 | 753 | } |
| 754 | + | |
| 755 | +/* | |
| 756 | +** Truncate a blob to the specified length in bytes. If truncation | |
| 757 | +** results in an incomplete UTF-8 sequence at the end, remove up | |
| 758 | +** to three more bytes back to the last complete UTF-8 sequence. | |
| 759 | +*/ | |
| 760 | +void blob_truncate_utf8(Blob *p, int sz){ | |
| 761 | + if( sz>=0 && sz<(int)(p->nUsed) ){ | |
| 762 | + p->nUsed = utf8_nearest_codepoint(p->aData,sz); | |
| 763 | + } | |
| 764 | +} | |
| 754 | 765 | |
| 755 | 766 | /* |
| 756 | 767 | ** Seek the cursor in a blob to the indicated offset. |
| 757 | 768 | */ |
| 758 | 769 | int blob_seek(Blob *p, int offset, int whence){ |
| 759 | 770 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -744,15 +744,26 @@ | |
| 744 | void blob_rewind(Blob *p){ |
| 745 | p->iCursor = 0; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | ** Truncate a blob back to zero length |
| 750 | */ |
| 751 | void blob_truncate(Blob *p, int sz){ |
| 752 | if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | ** Seek the cursor in a blob to the indicated offset. |
| 757 | */ |
| 758 | int blob_seek(Blob *p, int offset, int whence){ |
| 759 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -744,15 +744,26 @@ | |
| 744 | void blob_rewind(Blob *p){ |
| 745 | p->iCursor = 0; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | ** Truncate a blob to the specified length in bytes. |
| 750 | */ |
| 751 | void blob_truncate(Blob *p, int sz){ |
| 752 | if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | ** Truncate a blob to the specified length in bytes. If truncation |
| 757 | ** results in an incomplete UTF-8 sequence at the end, remove up |
| 758 | ** to three more bytes back to the last complete UTF-8 sequence. |
| 759 | */ |
| 760 | void blob_truncate_utf8(Blob *p, int sz){ |
| 761 | if( sz>=0 && sz<(int)(p->nUsed) ){ |
| 762 | p->nUsed = utf8_nearest_codepoint(p->aData,sz); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | ** Seek the cursor in a blob to the indicated offset. |
| 768 | */ |
| 769 | int blob_seek(Blob *p, int offset, int whence){ |
| 770 |
+5
-8
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -731,12 +731,12 @@ | ||
| 731 | 731 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 732 | 732 | } |
| 733 | 733 | wiki_hyperlink_override(0); |
| 734 | 734 | }else{ |
| 735 | 735 | if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){ |
| 736 | - blob_truncate(&comment, mxWikiLen); | |
| 737 | - blob_appendf(&comment, "..."); | |
| 736 | + blob_truncate_utf8(&comment, mxWikiLen); | |
| 737 | + blob_append(&comment, "...", 3); | |
| 738 | 738 | } |
| 739 | 739 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 740 | 740 | } |
| 741 | 741 | }else{ |
| 742 | 742 | if( bCommentGitStyle ){ |
| @@ -751,16 +751,13 @@ | ||
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | z[ii] = 0; |
| 754 | 754 | cgi_printf("%W",z); |
| 755 | 755 | }else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){ |
| 756 | - Blob truncated; | |
| 757 | - blob_zero(&truncated); | |
| 758 | - blob_append(&truncated, blob_buffer(&comment), mxWikiLen); | |
| 759 | - blob_append(&truncated, "...", 3); | |
| 760 | - @ %W(blob_str(&truncated)) | |
| 761 | - blob_reset(&truncated); | |
| 756 | + blob_truncate_utf8(&comment, mxWikiLen); | |
| 757 | + blob_append(&comment, "...", 3); | |
| 758 | + @ %W(blob_str(&comment)) | |
| 762 | 759 | drawDetailEllipsis = 0; |
| 763 | 760 | }else{ |
| 764 | 761 | cgi_printf("%W",blob_str(&comment)); |
| 765 | 762 | } |
| 766 | 763 | } |
| 767 | 764 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -731,12 +731,12 @@ | |
| 731 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 732 | } |
| 733 | wiki_hyperlink_override(0); |
| 734 | }else{ |
| 735 | if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){ |
| 736 | blob_truncate(&comment, mxWikiLen); |
| 737 | blob_appendf(&comment, "..."); |
| 738 | } |
| 739 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 740 | } |
| 741 | }else{ |
| 742 | if( bCommentGitStyle ){ |
| @@ -751,16 +751,13 @@ | |
| 751 | } |
| 752 | } |
| 753 | z[ii] = 0; |
| 754 | cgi_printf("%W",z); |
| 755 | }else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){ |
| 756 | Blob truncated; |
| 757 | blob_zero(&truncated); |
| 758 | blob_append(&truncated, blob_buffer(&comment), mxWikiLen); |
| 759 | blob_append(&truncated, "...", 3); |
| 760 | @ %W(blob_str(&truncated)) |
| 761 | blob_reset(&truncated); |
| 762 | drawDetailEllipsis = 0; |
| 763 | }else{ |
| 764 | cgi_printf("%W",blob_str(&comment)); |
| 765 | } |
| 766 | } |
| 767 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -731,12 +731,12 @@ | |
| 731 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 732 | } |
| 733 | wiki_hyperlink_override(0); |
| 734 | }else{ |
| 735 | if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){ |
| 736 | blob_truncate_utf8(&comment, mxWikiLen); |
| 737 | blob_append(&comment, "...", 3); |
| 738 | } |
| 739 | wiki_convert(&comment, 0, WIKI_INLINE); |
| 740 | } |
| 741 | }else{ |
| 742 | if( bCommentGitStyle ){ |
| @@ -751,16 +751,13 @@ | |
| 751 | } |
| 752 | } |
| 753 | z[ii] = 0; |
| 754 | cgi_printf("%W",z); |
| 755 | }else if( mxWikiLen>0 && (int)blob_size(&comment)>mxWikiLen ){ |
| 756 | blob_truncate_utf8(&comment, mxWikiLen); |
| 757 | blob_append(&comment, "...", 3); |
| 758 | @ %W(blob_str(&comment)) |
| 759 | drawDetailEllipsis = 0; |
| 760 | }else{ |
| 761 | cgi_printf("%W",blob_str(&comment)); |
| 762 | } |
| 763 | } |
| 764 |