You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michael Osipov (Jira)" <ji...@apache.org> on 2020/04/16 16:15:00 UTC
[jira] [Commented] (LANG-1533) RandomStringUtils.random() should
not include \u0000
[ https://issues.apache.org/jira/browse/LANG-1533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17085059#comment-17085059 ]
Michael Osipov commented on LANG-1533:
--------------------------------------
Maybe this should be tigher: printable ASCII chars only.
> RandomStringUtils.random() should not include \u0000
> -----------------------------------------------------
>
> Key: LANG-1533
> URL: https://issues.apache.org/jira/browse/LANG-1533
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.*
> Affects Versions: 3.8.1
> Reporter: Daniel Vega
> Priority: Minor
> Attachments: 0001-xxx.patch
>
>
> When generating random strings we should not include char 0x00 by default. This is problematic for many tools and libraries. For example, if we try to save this value on a PosgreSQL database we'll get:
>
> {quote}PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
> {quote}
>
> Currently we are avoiding some code code-point ranges. We should also skip {{codePoint=0}}
> {code:none}
> --- a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
> +++ b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
> @@ -400,6 +400,12 @@ public static String random(int count, int start, int end, final boolean letters
> if (chars == null) {
> codePoint = random.nextInt(gap) + start;
>
> + // Skip codePoint \u0000 because is problematic for some tools/libraries
> + if (codePoint==0) {
> + count++;
> + continue;
> + }
> +
> switch (Character.getType(codePoint)) {
> case Character.UNASSIGNED:
> case Character.PRIVATE_USE:
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)