Comments (5)
I believe that this is expected behavior.
How to check if IDs are valid?
Decoding IDs will usually produce some kind of numeric output, but that doesn't necessarily mean that the ID is canonical. To check that the ID is valid, you can re-encode decoded numbers and check that the ID matches.
The reason this is not done automatically is that if the default blocklist changes in the future, we don't want to automatically invalidate the ID that has been generated in the past and might now be matching a new blocklist word.
Source: https://sqids.org/faq#valid-ids
from sqids-java.
The following operation likely resulted in an overflow, exceeding the range of a long data type.
number = number * charLength + alphabet.indexOf(c);
@0x3333 The current code does not use BigInteger, and an overflow should result in an ArithmeticException. Do you agree with modifying it as follows?
number = Math.addExact(Math.multiplyExact(number, (long)charLength), alphabet.indexOf(c));
from sqids-java.
I don't believe we should change this. The problem is that the input is malformed, so this is expected.
This is the same even for the reference implementation in javascript. See: https://codesandbox.io/s/gallant-sky-g7qnrc?file=/src/index.ts
@4kimov what is your opinion on that?
from sqids-java.
To me, it sounds like a spec issue, not a Java implementation issue
As of right now, decode()
spec is designed to stop & return an empty array only when input is an empty string or there's a non-alphabet char in input.
All other scenarios are undefined -- which makes me lean towards leaving as-is, until spec is ironed out.
For now, the good news is that re-encoding would catch this.
from sqids-java.
@4kimov yep, sounds fair to me. Maybe add a more explicit entry in the FAQ?
@robhanlon22 will leave it as is until it is addressed in the reference implementation.
from sqids-java.
Related Issues (6)
- Init HOT 14
- Support for Java 9 Modules HOT 3
- Is it ready to use? HOT 40
- Cant find on maven HOT 1
- Fixed length encoded string
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 sqids-java.