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

[PATCH 1/3] Modify tr expressions so that xpg4/tr handles it on Solaris

From
Ben Walton <bdwalton@gmail.com>
Date
Jul 19, 2015, 18:00 UTC
Message-ID
<1437328836-19156-2-git-send-email-bdwalton@gmail.com>
In-Reply-To
<1437328836-19156-1-git-send-email-bdwalton@gmail.com>

It seems that xpg4/tr mishandles some strings involving [ not followed by a character class: % echo '[::1]' | /usr/xpg4/bin/tr -d '[]' [::1

% echo '[::1]' | /usr/xpg4/bin/tr -d '[' usr/xpg4/bin/tr: Bad string.

This was breaking two tests. To fix the issue, use the octal representations of [ and ] instead. Reference the octal expression as a newly exported variable so that it's shared across tests and more easily understood when reading it.

Signed-off-by: Ben Walton <bdwalton@gmail.com>
---
 t/t5500-fetch-pack.sh | 2 +-
 t/t5601-clone.sh      | 8 ++++----
 t/test-lib.sh         | 5 ++++-
 3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 3a9b775..2db9bde 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -547,7 +547,7 @@ check_prot_host_port_path () {
 		*ssh*)
 		pp=ssh
 		uah=userandhost
-		ehost=$(echo $3 | tr -d "[]")
+		ehost=$(echo $3 | tr -d "$squarebrackets")
 		diagport="Diag: port=$4"
 		;;
 		*)
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index bfdaf75..8299d14 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -445,7 +445,7 @@ test_expect_success 'clone ssh://host.xz:22/~repo' '
 #IPv6
 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
 do
-	ehost=$(echo $tuah | sed -e "s/1]:/1]/ "| tr -d "[]")
+	ehost=$(echo $tuah | sed -e "s/1]:/1]/ " | tr -d "$squarebrackets")
 	test_expect_success "clone ssh://$tuah/home/user/repo" "
 	  test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
 	"
@@ -454,7 +454,7 @@ done
 #IPv6 from home directory
 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
 do
-	euah=$(echo $tuah | tr -d "[]")
+	euah=$(echo $tuah | tr -d "$squarebrackets")
 	test_expect_success "clone ssh://$tuah/~repo" "
 	  test_clone_url ssh://$tuah/~repo $euah '~repo'
 	"
@@ -463,7 +463,7 @@ done
 #IPv6 with port number
 for tuah in [::1] user@[::1] [user@::1]
 do
-	euah=$(echo $tuah | tr -d "[]")
+	euah=$(echo $tuah | tr -d "$squarebrackets")
 	test_expect_success "clone ssh://$tuah:22/home/user/repo" "
 	  test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
 	"
@@ -472,7 +472,7 @@ done
 #IPv6 from home directory with port number
 for tuah in [::1] user@[::1] [user@::1]
 do
-	euah=$(echo $tuah | tr -d "[]")
+	euah=$(echo $tuah | tr -d "$squarebrackets")
 	test_expect_success "clone ssh://$tuah:22/~repo" "
 	  test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
 	"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 39da9c2..6b5b6cd 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -173,7 +173,10 @@ LF='
 # when case-folding filenames
 u200c=$(printf '\342\200\214')
 
-export _x05 _x40 _z40 LF u200c
+# [ and ], for use by tr commands.
+squarebrackets="\133\135"
+
+export _x05 _x40 _z40 LF u200c squarebrackets
 
 # Each test should start with something like this, after copyright notices:
 #
-- 
2.1.4
Previous: Ben WaltonNext: Eric Sunshine
Message 2 of 6 in “Adapt some tests to work around broken Solaris tools”
  1. Ben WaltonJul 19, 2015
  2. 1/3 Modify tr expressions so that xpg4/tr handles it on SolarisBen Walton, Jul 19, 2015
  3. Eric SunshineJul 19, 2015
  4. 2/3 Fix sed usage in tests to work around broken xpg4/sed on SolarisBen Walton, Jul 19, 2015
  5. 3/3 Fix sed usage in tests to work around broken xpg4/sed on SolarisBen Walton, Jul 19, 2015
  6. Johannes SixtJul 19, 2015

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.