Giter VIP home page Giter VIP logo

icecore-hashids's People

Contributors

arcticicestudio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

icecore-hashids's Issues

GitHub Open Source community standards

Adapt to the recommended community standards using the Open Source Guide to complete the projects community profile.

Code of Conduct

It should include sections about

  • what we believe in and how we act
  • unacceptable behavior
  • the responsibilities of the maintainer
  • the enforcement of the Code of Conduct
  • consequences for violations
  • the scope of the Code of Conduct

Contributing Guidelines

It should include sections about

SonarQube minor rule squid:S1643

The private method

hash(long, String) : String

and public API method

doEncode(long...) : Hashid

are conflicting with the SonarQube rule squid:S1643.

Solution

Use StringBuilder to improve the performance.

Unexpected NegativeArraySizeException

Metadata

Issue type: bug

Description

Unexpected NegativeArraySizeException is thrown for certain config and input values.

Steps to Reproduce

Following test is failing

    @Test
    public void testUnexpectedStringIndexOutOfBoundsException() {
        Hashids hashid = new Hashids.Builder()
                .features(HashidsFeature.EXCEPTION_HANDLING)
                .minLength(7)
                .salt("VHg5LVEz9UCpvi9zOfKmlbIBUWI=")
                .build();
        try {
            hashid.decodeOne("xxx");
            fail("Exception expected");
        } catch (Exception e) {
            // next line is failing since e is instance of NegativeArraySizeException
            assertThat(e, is(instanceOf(IllegalArgumentException.class)));
        }
    }

Expected Behavior

According to Javadoc - test case above should not fail.

Actual Behavior

Test case fails with unexpected NegativeArraySizeException.

Environment and Versions

IceCore Hashids: 0.4.0
OS: MacOS 11.0.1
JDK: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
Running in IDE and Gradle

Unexpected StringIndexOutOfBoundsException

Metadata

Issue type: bug

Description

Unexpected StringIndexOutOfBoundsException is thrown for certain config and input values.

Steps to Reproduce

Following test is failing

    @Test
    public void testUnexpectedStringIndexOutOfBoundsException() {
        Hashids hashid = new Hashids.Builder()
                .features(HashidsFeature.EXCEPTION_HANDLING)
                .minLength(7)
                .salt("6+7M7i7dNs4TFaV35iyItpRwMZ8=")
                .build();
        try {
            hashid.decodeOne("QdKNvK8");
            fail("Exception expected");
        } catch (Exception e) {
            // next line is failing since e is instance of StringIndexOutOfBoundsException
            assertThat(e, is(instanceOf(IllegalArgumentException.class)));
        }
    }

Expected Behavior

According to Javadoc - test case above should not fail.

Actual Behavior

Test case fails with unexpected StringIndexOutOfBoundsException.

Environment and Versions

IceCore Hashids: 0.4.0
OS: MacOS 11.0.1
JDK: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
Running in IDE and Gradle

Adapt new project setup and documentation style

This includes changes for build tools and all documentations:

  1. Refactor the .gitignore file
  2. Delete the .gitattributes file
  3. Refactor the pom.xml
  4. Update the README.md, CHANGELOG.md and LICENSE.md files to the new documentation style (Example: nord-java)
  5. Add a travis.yml and circle.yml configuration file
  6. Remove the COPYRIGHT.md file
  7. Move to the Apache 2.0 license
  8. Add the new project assets (SVG and AI files)
  9. Remove the verifications-project.xml configuration file
  10. Update the assembly-bin.xml configuration file

This issue is imported from the previous Bitbucket repository
ID: BBI #3

Short alphabet with large numbers throws exceptions

This will trigger an exception on decode:

Hashids hashids = new Hashids.Builder()
        .alphabet("0123456789ABCDEF")
        .features(HashidsFeature.EXCEPTION_HANDLING, HashidsFeature.NO_MAX_INTEROP_NUMBER_SIZE)
        .build();
String encode = hashids.encode(Long.MAX_VALUE);
hashids.decode(encode);
invalid hash: AB74D5546AE4B8E95697
java.lang.IllegalArgumentException: invalid hash: AB74D5546AE4B8E95697
	at com.arcticicestudio.icecore.hashids.Hashids.decode(Hashids.java:506)

Using a slightly different alphabet of 0123456789ABCDEFGHI causes a slightly different exception on decode:

number must not be less than zero: -9223372036854775597
java.lang.IllegalArgumentException: number must not be less than zero: -9223372036854775597
	at com.arcticicestudio.icecore.hashids.Hashids.encode(Hashids.java:285)
	at com.arcticicestudio.icecore.hashids.Hashids.decode(Hashids.java:504)

Alphabets longer than 20 characters, including the default, seem to avoid these errors.

Is com.arcticicestudio.icecore.hashids.Hashids#MIN_ALPHABET_LENGTH based on the max value in com.arcticicestudio.icecore.hashids.Hashids#MAX_INTEROP_NUMBER_SIZE, which is disabled via the NO_MAX_INTEROP_NUMBER_SIZE check?

Gitbook

Must be done after #9
Related to #10

The book should contain information about the public API, based on the redesign in #9, the Gitbook, the algorithm, the library itself like the design concept, guidelines and motivations.

The documentation is partially outdated for both style guidelines and topicality and should be adapted to the latest style guide and public API version based on the API redesign in #9.

It should also include some of the new project features and improvements:

  • Checkstyle integration added in #16
  • GitHub's Open Source Community Standards added in #12
  • GitHub's "Code Owner" ( #14 in PR #15 ) and "Issue- and Pull Request Template" ( #13 ) features
    Included in the contribution guide.

It should be deployed as GitHub Page to the gh-pages branch.

Maven POM refactoring

Has to be done after #16
Has to be done before #9

The Maven POM contains some outdated configurations which should be refactored.

  • Update plugin- and dependency versions
  • Remove the unnecessary comment documentation header
  • Fix the copyright year for generated JavaDoc
  • Add maven-enforcer-plugin
  • Remove unused profiles and configured core plugins
  • Remove unused test dependencies

Performance boost with char array instead of String operations

The private method consistentShuffle(String,String) operates with different methods of the String parameter alphabet like

substring(int, char)
charAt(int)

which can be replaced with a char[] instead of a char as temporary variable.

This removes five additional String operations/methods and six String concatenations to three simple array assignments.

Documentation redesign

Related to #11

The documentation is partially outdated for both style guidelines and topicality and should be adapted to the latest style guide and public API version based on the API redesign in #9.

Next to the refactoring some new features should also be covered by this including

  • the new Checkstyle integration added in #16 included in the contribution guide (#12)
  • the GitHub Open Source Community Standards added in #12
  • the new GitHub "Code Owner" ( #14 in PR #15 ) and "Issue- and Pull Request Template" ( #13 ) features included in the contribution guide (#12)

Salt length limit

Metadata

Issue type: bug/documentation improvement

Description

Only first x characters of a salt have effect on encoding result. It's undocumented and not clear whether it's a feature or a bug.

Steps to Reproduce

Following test is failing

    @Test
    public void testSaltLenght() {
        int limit = 128;
        int minHashLength = 7;
        long input = 1;
        for (int i = 0; i < limit; i++) {
            String prefix = org.apache.commons.lang3.RandomStringUtils.randomAscii(i);
            Hashids h1 = new Hashids.Builder().minLength(minHashLength).salt(prefix + "A").build();
            Hashids h2 = new Hashids.Builder().minLength(minHashLength).salt(prefix + "B").build();
            String s1 = h1.encode(input);
            String s2 = h2.encode(input);
            assertThat("i: " + i + "; prfix: '" + prefix + "'", s1, is(not(equalTo(s2))));
        }
    }

Expected Behavior

Test case above should not fail in case salt length is unlimited.

Actual Behavior

Test case fails usually around i = 45. Lowest I have seen is i = 32 which is likely related to randomly generated prefix value.

Input value looks to have effect too. When input = Hashids.MAX_INTEROP_NUMBER_SIZE test case fails usually when 41 < i < 44.

Example

Environment and Versions

IceCore Hashids: 0.4.0
OS: MacOS 11.0.1
JDK: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
Running in IDE and Gradle

Fix JavaDoc doclint compilation errors for self-closed paragraph tags

Since JDK 8u92 the JavaDoc linter will throw a compilation error for malformed JavaDoc comments.
Remove the self-closed </p> tags which are the last element before the JavaDoc tags.
Related files and lines:

  • Class: com.arcticicestudio.icecore.hashids.Hashids
    Lines: 48, 91, 92, 221

This issue is imported from the previous Bitbucket repository
ID: BBI #4

bug can't use long.max

can not use Long.MAX_VALUE

Hashids hashids = new Hashids();
String encode = hashids.encode(Long.MAX_VALUE);
System.out.println(encode);

API redesign

Must be done before #11
Must be done after #17

Public API

The public API is currently designed using a OOP layout by returning the Hashid class which stores the numbers and the hash value. It may be useful in some situations where the user like to store objects instead of primitives, but sue to the simplicity of the Hashid class it is easy for any user to implement such a small class on their own.

➡️ Redesign the API to only process (boxed) primitive types for both parameters and return types which will replace the Hashid class.

  • Public API redesign

Internal API

The internal API is unnecessary complicated when it comes to method complexity. The code style is too similar to the original implementation regarding variable naming and code structures. It does not make use of the advantages of Java 8 like streams and lambda expressions which are a great improvement for the performance of the algorithm.

➡️ The API should be redesigned regarding optimizations for Java 8 and the reduction of complexity for both public- and private methods.

  • Internal API redesign

Tests

The current code coverage is too low and should be increased by implementing unit tests for uncovered- and partially covered code blocks. The unit tests should also make use of JUnit's @Parameterized annotation to simplify each test case.

➡️ Add a test suite which runs the latest original hashids.js implementation against the results of this library to ensure full compatibility and integrity. This should be done by using the frontend-maven-plugin to make use of Node's npm ecosystem.

  • API tests redesign

Migrate to MIT license

Currently the project code is licensed under the Apache 2.0 license. This often causes problems when developers want to use the project or code parts of it in another project (mainly code editors and UI frameworks) licensed under a less restricted license.

The project and all of its port projects should migrate to the MIT license which is more open, unrestricted and the most used license for open source projects (Facebook recently also re-licensed React)

Increase unit test code coverage

The code coverage by unit tests is currently at 75%. More tests should be implemented for missing code lines.

  • Test the Hashid class for equals symmetric
@Override
public boolean equals(Object)

@Override
public int hashCode()

Checkstyle integration

Has to be done and merged before #17

Integrate Checkstyle into the development stack to comply with the Java Code Style Guide version 🏷️ 0.1.0.

The target version of the style guide configuration for Checkstyle is 8.0 which must be override the default version 6.11.2 of the latest maven-checkstyle-plugin version 2.17.

      <!-- .... -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
        <!-- .... -->
      </plugin>

The documentation will be added in #10 and #11.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.