Closed ThomasKlickermann closed 7 years ago
Hi, thanks will check. I did test it against php version. There is an unit test for decoding php hashid.
I'm also trying to use the Swift 3 update in a project so I spent some time seeing if I could reproduce this issue and it does look like there is a bug on master. I used this test with known hashes generated using js.
func testKnownHashesJS() {
// known hashed where generated with js Hashids implementation
// http://codepen.io/anon/pen/MbmpJP
let knownHashes: [String:[Int]] = ["gB0NV05e": [1]]
var equalCount = 0
let hashids = Hashids(salt: "this is my salt", minHashLength: 8, alphabet: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
for expectedHash in knownHashes.keys {
let values = knownHashes[expectedHash]
if let hash = hashids.encode(values!) {
NSLog("Expected hash: \(expectedHash)")
NSLog("Hash: \(hash)")
if (hash == expectedHash) {
equalCount += 1
}
}
}
XCTAssertEqual(equalCount, knownHashes.count)
}
This test fails on the master branch but passes on the swift-2.3 branch and in the Obj-C hashid project (https://github.com/DrGodCarl/hashids-objc).
i confirm, but try to change the salt and or the hash length. with demo salt and hash length of 10, it will give you another hash than the js version. same happens when you change the salt and use the default hash length.
i already compared the master php version with your swift version and also couldn't find any big differences. something is strange. when i try this for js and php version, both generate the same hash.
@willk37 Any ideas on what can be a reason? I'm trying to compare it with swift2 version which was ok.
@willk37 I do think your pull was a solution. btw the same problem was there also in Swift2 version
update doesn't conform to other hashids libraries ... try using generated hash from swift and decode with php or js library of hashids.
the encode does something else then the other version of hashids.org libraries. the decode encodes the swift 3 version and the version of other libraries from hashids.org