Comments (7)
Should have mentioned this was using the default arguments except a minimum hash length of 8. The exception with 1 character still happens using any minimum hash lengths including the default (0).
The System.ArgumentException: Destination is too short. (Parameter 'destination') happens whenever a string is passed in which is less than the minimum hash length.
from hashids.net.
Hi, I just came across this with a Unit test trying to decode the phrase "Junk"
Even the TryDecodeSingle fails? would have thought that one should have just returned false instead of throwing an Exception?
I ended up wrapping the whole thing in a Try Catch, which works, but is this intended behaviour?
from hashids.net.
@CliveBennett I agree, a function named "TryBlabla" shouldn't ever produce an exception imo if we want to follow the C# naming "standard"...
We should fix that.
from hashids.net.
Sorry I'm not able to work out a Pull request, but in the function "private long GetNumberFrom(string hash)" changing:
Span<char> resultBuffer = stackalloc char[guardedHash.Length];
to
var resultBufferLength = Math.Max(Math.Max(guardedHash.Length, 20), _minHashLength);`
Span<char> resultBuffer = stackalloc char[resultBufferLength];
seems to fix things. The constant length 20 seems to be used commonly through the algorithm though I don't know why. Also could add tests:
[Fact]
void Issue_75_1_character_hash_string_should_not_throw_out_of_range_exception()
{
var hashids = new Hashids("salt");
Assert.Throws<NoResultException>(() => hashids.DecodeSingle("a"));
}
[Fact]
void Issue_75_too_short_hash_string_should_not_throw_argument_exception()
{
var hashids = new Hashids("salt", 40);
Assert.Throws<NoResultException>(() => hashids.DecodeSingle("ab"));
}
from hashids.net.
thanks @crmeadowcroft for pointing that out, added a new PR to fix
from hashids.net.
fixed in 1.6.1: https://www.nuget.org/packages/Hashids.net/1.6.1
from hashids.net.
Thanks for fixing the bug I introduced in #65
from hashids.net.
Related Issues (20)
- Optimization: decode a single ID without allocating an array HOT 4
- how to Creates short unique ids from integers. (only positive numbers & zero) HOT 1
- Bug on long encoding with 16 alphabet chars HOT 8
- Using multiple options for encoding/decoding HOT 1
- Hashids not generating with proper minhashlength HOT 1
- HashIds not working after adding custom Output formatter HOT 2
- How do I get HashIDs of a specific length? HOT 1
- How use id with Guid/UUID/Sequential Guid HOT 1
- Is there a guarantee of encoded sequence uniqueness with differing salts? HOT 4
- Insufficient Variation In Generated HashIds HOT 1
- Document the effective character limit of the salt HOT 5
- Decoding input smaller than minHashLength unhandled exceptions are thrown HOT 4
- Json support? HOT 3
- Regarding HashidsNet HOT 1
- Website seems down HOT 2
- Valid use-case for library? HOT 1
- Is this lib still being maintained? HOT 2
- Decode null string thows NullReferenceException HOT 1
- Same id generated for different integers HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashids.net.