# [PATCH 1/2] Modify tr expression so that xpg4/tr handles it on Solaris

3 messages from 2015-07-18 to 2015-07-19. Participants: Ben Walton, Eric Sunshine.
Thread: https://gitlist.dev/t/39884

## Ben Walton, 2015-07-18 15:21

Subject: [PATCH 1/2] Modify tr expression so that xpg4/tr handles it on Solaris
Message-ID: <1437232877-27897-1-git-send-email-bdwalton@gmail.com>
URL: https://gitlist.dev/e/1437232877-27897-1-git-send-email-bdwalton%40gmail.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.

Signed-off-by: Ben Walton <bdwalton@gmail.com>
---
 t/t5500-fetch-pack.sh |    2 +-
 t/t5601-clone.sh      |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 3a9b775..5bc4da9 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 "\133\135")
 		diagport="Diag: port=$4"
 		;;
 		*)
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index bfdaf75..fa6be3c 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 "\133\135")
 	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 "\133\135")
 	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 "\133\135")
 	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 "\133\135")
 	test_expect_success "clone ssh://$tuah:22/~repo" "
 	  test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
 	"
-- 
1.7.10.4

```

## Eric Sunshine, 2015-07-19 03:31

Subject: Re: [PATCH 1/2] Modify tr expression so that xpg4/tr handles it on Solaris
Message-ID: <CAPig+cQYROsp4nsEj1cJ=W+BtxO5iQ0_UHUaJHScpN7iQBpi6A@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQYROsp4nsEj1cJ%3DW%2BBtxO5iQ0_UHUaJHScpN7iQBpi6A%40mail.gmail.com
In-Reply-To: <1437232877-27897-1-git-send-email-bdwalton@gmail.com>

```
On Sat, Jul 18, 2015 at 11:21 AM, Ben Walton <bdwalton@gmail.com> wrote:
> 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.

I suppose that "tr -d ']['" also gives a "Bad string." error?

> This was breaking two tests. To fix the issue, use the octal
> representations of [ and ] instead.
>
> Signed-off-by: Ben Walton <bdwalton@gmail.com>
> ---
>  t/t5500-fetch-pack.sh |    2 +-
>  t/t5601-clone.sh      |    8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
> index 3a9b775..5bc4da9 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 "\133\135")

These octal values are somewhat opaque. To make this more
self-documenting, would it make sense instead to define a global
variable named 'brackets' or 'squarebrackets' (or something) and then
reference that variable in each of the 'tr' commands?

    brackets='\133\135'
    ...
    ehost=$(echo $3 | tr -d $brackets)

>                 diagport="Diag: port=$4"
>                 ;;
>                 *)
> diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
> index bfdaf75..fa6be3c 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 "\133\135")
>         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 "\133\135")
>         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 "\133\135")
>         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 "\133\135")
>         test_expect_success "clone ssh://$tuah:22/~repo" "
>           test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
>         "
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Eric Sunshine, 2015-07-19 03:45

Subject: Re: [PATCH 1/2] Modify tr expression so that xpg4/tr handles it on Solaris
Message-ID: <CAPig+cQ7E5+0aZ09Bhv+j_wmBkOq9kbqUyqxTn=qVV8+j7Mbrw@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQ7E5%2B0aZ09Bhv%2Bj_wmBkOq9kbqUyqxTn%3DqVV8%2Bj7Mbrw%40mail.gmail.com
In-Reply-To: <CAPig+cQYROsp4nsEj1cJ=W+BtxO5iQ0_UHUaJHScpN7iQBpi6A@mail.gmail.com>

```
On Sat, Jul 18, 2015 at 11:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Sat, Jul 18, 2015 at 11:21 AM, Ben Walton <bdwalton@gmail.com> wrote:
>> 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.
>>
>> Signed-off-by: Ben Walton <bdwalton@gmail.com>
>> ---
>> -               ehost=$(echo $3 | tr -d "[]")
>> +               ehost=$(echo $3 | tr -d "\133\135")
>
> These octal values are somewhat opaque. To make this more
> self-documenting, would it make sense instead to define a global
> variable named 'brackets' or 'squarebrackets' (or something) and then
> reference that variable in each of the 'tr' commands?
>
>     brackets='\133\135'
>     ...
>     ehost=$(echo $3 | tr -d $brackets)

Quoted, of course:

    ehost=$(echo $3 | tr -d "$brackets")

```
