| commit | fd866a9c2d6c69f9f6462a5e498b58293597d611 | [log] [tgz] | 
|---|---|---|
| author | Fabrice Benhamouda <1146316+fabrice102@users.noreply.github.com> | Tue Sep 10 20:47:24 2024 -0400 | 
| committer | GitHub <noreply@github.com> | Tue Sep 10 20:47:24 2024 -0400 | 
| tree | 016eb0331f73b0b519563e62f2a7ce258165d586 | |
| parent | d1bf9bfe747d5ad8a14cc1f65e6876a30a1bc866 [diff] | 
Fix handling of non-ASCII letters & numbers in RandomStringUtils (#1273) An optimization introduced in commit f382d61a03778ccf838c6c051bd8692e4834dec2 incorrectly assumed that letters and numbers/digits are ASCII. For example, `RandomStringUtils.random(1, 0x4e00, 0x4e01, true, false)` would take too long to terminate and would not output the correct answer, that is the string with a single character `0x4e00`. The issue is that `end` would be replaced by `'z' + 1 = 123` (the latest ASCII letter + 1) there: https://github.com/apache/commons-lang/blob/f382d61a03778ccf838c6c051bd8692e4834dec2/src/main/java/org/apache/commons/lang3/RandomStringUtils.java#L266-L270 Thus, we would have `end < start` and `gap = end - start < 0`. This PR fixes this issue by restricting the optimization to cases where only ASCII characters are requested, that is `end < 0x7f`. This PR also slightly clarifies the code, using constant variables instead of '0', '9', 'A', and 'z'. The PR also includes two regression tests. Co-authored-by: Fabrice Benhamouda <yfabrice@amazon.com>
Apache Commons Lang, a package of Java utility classes for the classes that are in java.lang's hierarchy, or are considered to be so standard as to justify existence in java.lang.
The code is tested using the latest revision of the JDK for supported LTS releases: 8, 11, 17 and 21 currently. See https://github.com/apache/commons-lang/blob/master/.github/workflows/maven.yml
Please ensure your build environment is up-to-date and kindly report any build issues.
More information can be found on the Apache Commons Lang homepage. The Javadoc can be browsed. Questions related to the usage of Apache Commons Lang should be posted to the user mailing list.
You can download source and binaries from our download page.
Alternatively, you can pull it from the central Maven repositories:
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.17.0</version> </dependency>
Building requires a Java JDK and Apache Maven. The required Java version is found in the pom.xml as the maven.compiler.source property.
From a command shell, run mvn without arguments to invoke the default Maven goal to run all tests and checks.
We accept Pull Requests via GitHub. The developer mailing list is the main channel of communication for contributors. There are some guidelines which will make applying PRs easier for us:
mvn.mvn (by itself), this runs the default goal, which contains all build checks.mvn clean site -Dcommons.jacoco.haltOnFailure=falseIf you plan to contribute on a regular basis, please consider filing a contributor license agreement. You can learn more about contributing via GitHub in our contribution guidelines.
This code is licensed under the Apache License v2.
See the NOTICE.txt file for required notices and attributions.
You like Apache Commons Lang? Then donate back to the ASF to support development.
Please see the list of components