git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/7] utf8: fix off-by-one wrapping of text

From
JSJan H. Schönherr <schnhrr@cs.tu-berlin.de>
Date
Oct 18, 2012, 14:43 UTC
Message-ID
<1350571414-17907-2-git-send-email-schnhrr@cs.tu-berlin.de>
In-Reply-To
<1350571414-17907-1-git-send-email-schnhrr@cs.tu-berlin.de>
From: Jan H. Schönherr <schnhrr@cs.tu-berlin.de>

The wrapping logic in strbuf_add_wrapped_text() does currently not allow lines that entirely fill the allowed width, instead it wraps the line one character too early.

For example, the text "This is the sixth commit." formatted via "%w(11,1,2)" (wrap at 11 characters, 1 char indent of first line, 2 char indent of following lines) results in four lines: " This is", " the", " sixth", " commit." This is wrong, because " the sixth" is exactly 11 characters long, and thus allowed.

Fix this by allowing the (width+1) character of a line to be a valid wrapping point if it is a whitespace character.

Signed-off-by: Jan H. Schönherr <schnhrr@cs.tu-berlin.de>
---
v2: new patch, result of v1 discussion
---
 t/t4202-log.sh | 4 ++--
 utf8.c         | 2 +-
 2 Dateien geändert, 3 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index b3ac6be..584e3d8 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -72,9 +72,9 @@ cat > expect << EOF
   commit.
 EOF
 
-test_expect_success 'format %w(12,1,2)' '
+test_expect_success 'format %w(11,1,2)' '
 
-	git log -2 --format="%w(12,1,2)This is the %s commit." > actual &&
+	git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
 	test_cmp expect actual
 '
 
diff --git a/utf8.c b/utf8.c
index a544f15..28791a7 100644
--- a/utf8.c
+++ b/utf8.c
@@ -353,7 +353,7 @@ retry:
 
 		c = *text;
 		if (!c || isspace(c)) {
-			if (w < width || !space) {
+			if (w <= width || !space) {
 				const char *start = bol;
 				if (!c && text == start)
 					return w;
-- 
1.7.12
Previous: Jan H. SchönherrNext: Jan H. Schönherr
Message 2 of 8 in “Cure some format-patch wrapping and encoding issues”
  1. 0/7 Cure some format-patch wrapping and encoding issuesJan H. Schönherr, Oct 18, 2012
  2. 1/7 utf8: fix off-by-one wrapping of textJan H. Schönherr, Oct 18, 2012
  3. 2/7 format-patch: do not wrap non-rfc2047 headers too earlyJan H. Schönherr, Oct 18, 2012
  4. 3/7 format-patch: do not wrap rfc2047 encoded headers too lateJan H. Schönherr, Oct 18, 2012
  5. 4/7 format-patch: introduce helper function last_line_length()Jan H. Schönherr, Oct 18, 2012
  6. 5/7 format-patch: make rfc2047 encoding more strictJan H. Schönherr, Oct 18, 2012
  7. 6/7 format-patch: fix rfc2047 address encoding with respect to rfc822 specialsJan H. Schönherr, Oct 18, 2012
  8. 7/7 format-patch tests: check quoting/encoding in To: and Cc: headersJan H. Schönherr, Oct 18, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.