You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/07/05 19:14:00 UTC

[jira] [Work logged] (LANG-1533) RandomStringUtils.random() should not include \u0000

     [ https://issues.apache.org/jira/browse/LANG-1533?focusedWorklogId=788022&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-788022 ]

ASF GitHub Bot logged work on LANG-1533:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Jul/22 19:13
            Start Date: 05/Jul/22 19:13
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on code in PR #654:
URL: https://github.com/apache/commons-lang/pull/654#discussion_r914127759


##########
src/main/java/org/apache/commons/lang3/RandomStringUtils.java:
##########
@@ -404,6 +404,7 @@ public static String random(int count, int start, int end, final boolean letters
                 case Character.UNASSIGNED:
                 case Character.PRIVATE_USE:
                 case Character.SURROGATE:
+                case Character.CONTROL:

Review Comment:
   That does not look right IMO because it excludes the TAB character.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 788022)
    Time Spent: 40m  (was: 0.5h)

> 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
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> 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 in 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.20.10#820010)