+4
-4
atproto/syntax/aturi.go
+4
-4
atproto/syntax/aturi.go
···
62
// Returns path segment, without leading slash, as would be used in an atproto repository key. Or empty string if there is no path.
63
func (n ATURI) Path() string {
64
parts := strings.SplitN(string(n), "/", 5)
65
-
if len(parts) < 3 {
66
// something has gone wrong (would not validate)
67
return ""
68
}
69
-
if len(parts) == 3 {
70
-
return parts[2]
71
}
72
-
return parts[2] + "/" + parts[3]
73
}
74
75
// Returns a valid NSID if there is one in the appropriate part of the path, otherwise empty.
···
62
// Returns path segment, without leading slash, as would be used in an atproto repository key. Or empty string if there is no path.
63
func (n ATURI) Path() string {
64
parts := strings.SplitN(string(n), "/", 5)
65
+
if len(parts) < 4 {
66
// something has gone wrong (would not validate)
67
return ""
68
}
69
+
if len(parts) == 4 {
70
+
return parts[3]
71
}
72
+
return parts[3] + "/" + parts[4]
73
}
74
75
// Returns a valid NSID if there is one in the appropriate part of the path, otherwise empty.
+26
-1
atproto/syntax/aturi_test.go
+26
-1
atproto/syntax/aturi_test.go
···
20
if len(line) == 0 || line[0] == '#' {
21
continue
22
}
23
-
_, err := ParseATURI(line)
24
if err != nil {
25
fmt.Println("FAILED, GOOD: " + line)
26
}
27
assert.NoError(err)
28
}
29
assert.NoError(scanner.Err())
30
}
···
67
rkey := uri.RecordKey()
68
assert.Equal(parts[3], rkey.String())
69
}
70
71
}
72
73
func TestATURINormalize(t *testing.T) {
···
93
_ = bad.RecordKey()
94
_ = bad.Normalize()
95
_ = bad.String()
96
}
97
}
···
20
if len(line) == 0 || line[0] == '#' {
21
continue
22
}
23
+
aturi, err := ParseATURI(line)
24
if err != nil {
25
fmt.Println("FAILED, GOOD: " + line)
26
}
27
assert.NoError(err)
28
+
29
+
// check that Path() is working
30
+
col := aturi.Collection()
31
+
rkey := aturi.RecordKey()
32
+
if rkey != "" {
33
+
assert.Equal(col.String()+"/"+rkey.String(), aturi.Path())
34
+
} else if col != "" {
35
+
assert.Equal(col.String(), aturi.Path())
36
+
}
37
}
38
assert.NoError(scanner.Err())
39
}
···
76
rkey := uri.RecordKey()
77
assert.Equal(parts[3], rkey.String())
78
}
79
+
}
80
81
+
func TestATURIPath(t *testing.T) {
82
+
assert := assert.New(t)
83
+
84
+
uri1, err := ParseATURI("at://did:abc:123/io.nsid.someFunc/record-key")
85
+
assert.NoError(err)
86
+
assert.Equal("io.nsid.someFunc/record-key", uri1.Path())
87
+
88
+
uri2, err := ParseATURI("at://did:abc:123/io.nsid.someFunc")
89
+
assert.NoError(err)
90
+
assert.Equal("io.nsid.someFunc", uri2.Path())
91
+
92
+
uri3, err := ParseATURI("at://did:abc:123")
93
+
assert.NoError(err)
94
+
assert.Equal("", uri3.Path())
95
}
96
97
func TestATURINormalize(t *testing.T) {
···
117
_ = bad.RecordKey()
118
_ = bad.Normalize()
119
_ = bad.String()
120
+
_ = bad.Path()
121
}
122
}