-
Notifications
You must be signed in to change notification settings - Fork 24
Incompatibility with "zii" #80
Comments
I should note that this is where I'm trying to use this: zii is pulled in a couple levels of dependencies down, so it's not an easy one for us to just patch out. |
Where did you get the CID "zQmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"? It's not valid. I think there may be some bad generation of the hashes in one of the dependencies that's incorrectly appending 'z' instead of properly processing it. |
That comes from this: Which calls this: Which prepends a "z" and then tries to decode. However, the problem happens before it even gets to the point where it would be valid or not. It comes from autodetection of encoding of hashes which start with a "z" trigger. If they start with the letter "z", this is true if zii is active: Line 117 in c373031
So it returns from here: Line 118 in c373031
Instead of falling back to: Line 119 in c373031
And returning from: Line 120 in c373031
It triggers the zii override gets because there is nothing in constants.names with the key "z". But because zii adds a prototype for that, the All that to say...swapping those two fixes the conflict. |
Well, this is the type of second-degree problems mutating Object prototype (what IIUC we could accept a PR that protects our libs from this malevolence and adds additional check in: Lines 116 to 122 in c373031
Something like: - if (constants.names[nameOrCode]) {
+ if (constants.names[nameOrCode] && typeof constants.codes[nameOrCode] === 'string') { Thoughts? |
You'll hear no argument from me on that. But unfortunately, it's a dependency that's buried rather deep within other stuff. I do have an open issue filed with that project to try to eliminate zii, but they use it a lot, so it's probably going to be quite a while before that happens.
That should work. Or pull request #81, which I tested with zii to make sure it works. |
However it gets fixed, if you want to test it, all you have to do is |
Turns out this didn't quite work. (a) It needs to check |
damn i dont even know what to say @multiformats/javascript-team thoughts ? |
Well ... the correct response is to say that But we could deal with it directly without too much pain though and won't feel like a hack because it's technically appropriate anyway: diff --git a/src/index.js b/src/index.js
index df66bad..8bda372 100644
--- a/src/index.js
+++ b/src/index.js
@@ -114,9 +114,9 @@ function validEncode (name, buf) {
* @throws {Error} Will throw if the encoding is not supported
*/
function encoding (nameOrCode) {
- if (constants.names[/** @type {BaseName} */(nameOrCode)]) {
+ if (constants.names.hasOwnProperty(/** @type {BaseName} */(nameOrCode))) {
return constants.names[/** @type {BaseName} */(nameOrCode)]
- } else if (constants.codes[/** @type {BaseCode} */(nameOrCode)]) {
+ } else if (constants.codes.hasOwnProperty(/** @type {BaseCode} */(nameOrCode))) {
return constants.codes[/** @type {BaseCode} */(nameOrCode)]
} else {
throw new Error(`Unsupported encoding: ${nameOrCode}`) (edit: the types are probably not going to be happy here, maybe good enough to just remove the type cast although I'm not sure what the flow-on effects will be) |
I would agree with this sentiment, and have expressed such in the bug report for the project that pulls it in. But, it's a core package for JavaScript Scuttlebutt clients, so it's not like we can just drop it and it would be difficult for us to reimplement. So...it is what it is. That change looks to me like it should work. I haven't tested it, but it looks like it would solve the problem. |
@rvagg @hugomrdias See #84. |
Thank you for the help with this! Looking forward to trying to integrate IPFS into our application. |
Describe the bug
If the package "zii" is installed due to a dependency somewhere else in an npm project including js-multibase (in my case, from ipfs-repo-migrations from ipfs-core), this function:
js-multibase/src/index.js
Line 116 in c373031
...no longer works for types which use a code of "z". This happens in my case from here:
https://github.com/ipfs/js-ipfs-repo-migrations/blob/425d53c5f2ef2d89b11d2cfc33362d5ebfad81a5/migrations/migration-9/utils.js#L10
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It decodes.
Actual behavior
I get this error:
TypeError: enc.decode is not a function
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: