github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/name_encoding_test.go (about)

     1  // Copyright 2021 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libkb
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestNameEncoding(t *testing.T) {
    14  	var fixture = [][2]string{
    15  		{`foo`, `foo`},
    16  		{`foo\bar`, `foo‰5cbar`},
    17  		{`foo‰bar`, `foo‰2030bar`},
    18  		{`foo‰\bar`, `foo‰2030‰5cbar`},
    19  		{`foo%bar`, `foo%bar`},
    20  		{"<", "‰3c"},
    21  		{">", "‰3e"},
    22  		{":", "‰3a"},
    23  		{"\"", "‰22"},
    24  		{"/", "‰2f"},
    25  		{"\\", "‰5c"},
    26  		{"|", "‰7c"},
    27  		{"?", "‰3f"},
    28  		{"*", "‰2a"},
    29  	}
    30  
    31  	for _, entry := range fixture {
    32  		require.Equal(t, entry[1], EncodeKbfsNameForWindows(entry[0]))
    33  
    34  		kbfsName, err := DecodeWindowsNameForKbfs(entry[1])
    35  		require.NoError(t, err)
    36  		require.Equal(t, entry[0], kbfsName)
    37  
    38  	}
    39  
    40  	_, err := DecodeWindowsNameForKbfs(`a\b`)
    41  	require.Error(t, err)
    42  }