| 90 | } |
| 91 | |
| 92 | func (e *defaultPathEncoder) Decode( |
| 93 | encodedPath string, |
| 94 | ) ([]string, error) { |
| 95 | if encodedPath == "" { |
| 96 | return rootPath, nil |
| 97 | } |
| 98 | |
| 99 | path := make([]string, 0, 3) |
| 100 | var b strings.Builder |
| 101 | escaped := false |
| 102 | for _, r := range encodedPath { |
| 103 | if r == utf8.RuneError { |
| 104 | return nil, serviceerror.NewInvalidArgumentf("encodedPath contains invalid UTF-8 code point: %v", encodedPath) |
| 105 | } |
| 106 | |
| 107 | if escaped { |
| 108 | _, _ = b.WriteRune(r) |
| 109 | escaped = false |
| 110 | continue |
| 111 | } |
| 112 | |
| 113 | if r == '\\' { |
| 114 | escaped = true |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | if r == '$' || r == '#' { |
| 119 | path = append(path, b.String()) |
| 120 | b.Reset() |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | _, _ = b.WriteRune(r) |
| 125 | } |
| 126 | if escaped { |
| 127 | return nil, serviceerror.NewInternalf("encoded path ends with escape character: %v", encodedPath) |
| 128 | } |
| 129 | |
| 130 | path = append(path, b.String()) |
| 131 | return path, nil |
| 132 | } |