-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: don't throw on invalid b58 string in getPeerId #43
Changes from 4 commits
2663933
4e0b275
47d39b5
bc74080
d431981
32d3bc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ Multiaddr.prototype.inspect = function inspect () { | |
Multiaddr.prototype.protos = function protos () { | ||
return map(this.protoCodes(), function (code) { | ||
return extend(protocols(code)) | ||
// copy to prevent users from modifying the internal objs. | ||
// copy to prevent users from modifying the internal objs. | ||
}) | ||
} | ||
|
||
|
@@ -249,13 +249,17 @@ Multiaddr.prototype.decapsulate = function decapsulate (addr) { | |
* } | ||
*/ | ||
Multiaddr.prototype.getPeerId = function getPeerId () { | ||
let b58str = this.stringTuples().filter((tuple) => { | ||
if (tuple[0] === protocols.names['ipfs'].code) { | ||
return true | ||
} | ||
})[0][1] | ||
let b58str = null | ||
try { | ||
b58str = this.stringTuples().filter((tuple) => { | ||
if (tuple[0] === protocols.names['ipfs'].code) { | ||
return true | ||
} | ||
})[0][1] | ||
|
||
bs58.decode(b58str) | ||
} catch (e) {} | ||
|
||
bs58.decode(b58str) | ||
return b58str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dryajov this way you are silencing the error and returning null. Why do you think this is a better approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want the utility function to be more ergonomic, in the majority of cases you want to just |
||
} | ||
|
||
|
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.
ah, I think you might be asking about this part here?
I should be clearing b58str in the catch, I'll fix that. Otherwise, I think returning
null
on invalid/empty ids is an acceptable solutions, as long as no malformed ids are returned?