Fossil SCM

Tweak [1f20d61a07] to avoid broken UTF-8 sequences at the end of truncated comments.

florian 2026-02-07 15:08 trunk
Commit f661b8de491e40daa44c37eba66f02cca0acfa0cc2a683bc577071412699b1ea
2 files changed +12 -1 +5 -8
+12 -1
--- src/blob.c
+++ src/blob.c
@@ -744,15 +744,26 @@
744744
void blob_rewind(Blob *p){
745745
p->iCursor = 0;
746746
}
747747
748748
/*
749
-** Truncate a blob back to zero length
749
+** Truncate a blob to the specified length in bytes.
750750
*/
751751
void blob_truncate(Blob *p, int sz){
752752
if( sz>=0 && sz<(int)(p->nUsed) ) p->nUsed = sz;
753753
}
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
+}
754765
755766
/*
756767
** Seek the cursor in a blob to the indicated offset.
757768
*/
758769
int blob_seek(Blob *p, int offset, int whence){
759770
--- 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 @@
731731
wiki_convert(&comment, 0, WIKI_INLINE);
732732
}
733733
wiki_hyperlink_override(0);
734734
}else{
735735
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);
738738
}
739739
wiki_convert(&comment, 0, WIKI_INLINE);
740740
}
741741
}else{
742742
if( bCommentGitStyle ){
@@ -751,16 +751,13 @@
751751
}
752752
}
753753
z[ii] = 0;
754754
cgi_printf("%W",z);
755755
}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))
762759
drawDetailEllipsis = 0;
763760
}else{
764761
cgi_printf("%W",blob_str(&comment));
765762
}
766763
}
767764
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button