-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add input cleaner #51
Conversation
Specifically I originally wanted this to do this: |
Pinging @Stebalien for opinions on this. |
I'm really wary of stuff like this. What if we were to match URLs only? That is, check:
|
2510ef3
to
cba2051
Compare
I changed this so that we first try to use Regex changed Added a simple test as well. |
877795e
to
eb0b41c
Compare
The CI was not happy about the lack of execute permission on the test script file. This should be good for real now (assuming it passes). Edit: I lied I left an additional test in there by mistake |
If that's too specific |
main.go
Outdated
return ipfsPath, nil | ||
} | ||
// allow HTTP gateway URLs as input as well | ||
matches := regexp.MustCompile(`^https?://.*(/(?:ipfs|ipns|ipld)/.+)$`).FindStringSubmatch(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
is greedy. This'll parse http://bla.com/ipfs/QmA/ipfs/foobar
as /ipfs/foobar
. What if we just parsed the input as a URL and took the path? IMO, it's reasonable to assume that gateways are run on their own origin (for security reasons).
28576b3
to
0af4734
Compare
Much better! I also added the handling for these ipfs/ipfs-companion#533 Edit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits but otherwise LGTM.
main.go
Outdated
|
||
switch proto := u.Scheme; proto { | ||
case "ipfs", "ipld", "ipns": | ||
return ipath.ParsePath(gopath.Join(fmt.Sprintf("/%s/", proto), u.Host, u.Path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We can just write gopath.Join("/", proto, u.Host, u.Path)
.
main.go
Outdated
switch proto := u.Scheme; proto { | ||
case "ipfs", "ipld", "ipns": | ||
return ipath.ParsePath(gopath.Join(fmt.Sprintf("/%s/", proto), u.Host, u.Path)) | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be conservative for now.
case "https", "http":
Accept HTTP gateway URLs and IPFS URIs as arguments
So that input such as
http://localhost:8080/ipfs/QmcbLLZJa9oXnYTZWfS4T16n8B2mHFZkAzkKBNdGVzgG8g
,https://ipfs.io/ipfs/QmcbLLZJa9oXnYTZWfS4T16n8B2mHFZkAzkKBNdGVzgG8g
, etc. may be passed in and turned into proper references (/ipfs/QmcbLLZJa9oXnYTZWfS4T16n8B2mHFZkAzkKBNdGVzgG8g
)If nothing is found the input string is returned so that it may pass or fail by
path.ParsePath
later.Blocked by: #50
submitting now so I don't forget.