This repository was archived by the owner on Jun 20, 2023. It is now read-only.
File tree 2 files changed +17
-6
lines changed
2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ func ParsePath(txt string) (Path, error) {
106
106
// if the path doesnt begin with a '/'
107
107
// we expect this to start with a hash, and be an 'ipfs' path
108
108
if parts [0 ] != "" {
109
- if _ , err := ParseCidToPath (parts [0 ]); err != nil {
109
+ if _ , err := cid . Decode (parts [0 ]); err != nil {
110
110
return "" , ErrBadPath
111
111
}
112
112
// The case when the path starts with hash without a protocol prefix
@@ -117,11 +117,17 @@ func ParsePath(txt string) (Path, error) {
117
117
return "" , ErrBadPath
118
118
}
119
119
120
- if parts [1 ] == "ipfs" {
121
- if _ , err := ParseCidToPath (parts [2 ]); err != nil {
120
+ //TODO: make this smarter
121
+ switch parts [1 ] {
122
+ case "ipfs" , "ipld" :
123
+ // Validate Cid.
124
+ _ , err := cid .Decode (parts [2 ])
125
+ if err != nil {
122
126
return "" , err
123
127
}
124
- } else if parts [1 ] != "ipns" && parts [1 ] != "ipld" { //TODO: make this smarter
128
+ case "ipns" :
129
+ // No validation.
130
+ default :
125
131
return "" , ErrBadPath
126
132
}
127
133
Original file line number Diff line number Diff line change @@ -18,9 +18,14 @@ func TestPathParsing(t *testing.T) {
18
18
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n" : true ,
19
19
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n" : false ,
20
20
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a" : false ,
21
- "/ipfs/" : false ,
22
- "ipfs/" : false ,
21
+ "/ipfs/foo" : false ,
22
+ "/ipfs/" : false ,
23
+ "ipfs/" : false ,
23
24
"ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n" : false ,
25
+ "/ipld/foo" : false ,
26
+ "/ipld/" : false ,
27
+ "ipld/" : false ,
28
+ "ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n" : false ,
24
29
}
25
30
26
31
for p , expected := range cases {
You can’t perform that action at this time.
0 commit comments