Github user jiazhai commented on a diff in the pull request:

    
https://github.com/apache/incubator-distributedlog/pull/130#discussion_r117600348
  
    --- Diff: 
distributedlog-core/src/main/java/org/apache/distributedlog/util/DLUtils.java 
---
    @@ -281,41 +281,89 @@ public static boolean isReservedStreamName(String 
name) {
         }
     
         /**
    -     * Validate the stream name.
    +     * Validate the log name.
          *
    -     * @param nameOfStream
    -     *          name of stream
    +     * @param logName
    +     *          name of log
          * @throws InvalidStreamNameException
          */
    -    public static void validateName(String nameOfStream)
    +    public static String validateAndNormalizeName(String logName)
                 throws InvalidStreamNameException {
    -        String reason = null;
    -        char chars[] = nameOfStream.toCharArray();
    -        char c;
    -        // validate the stream to see if meet zookeeper path's requirement
    -        for (int i = 0; i < chars.length; i++) {
    -            c = chars[i];
    -
    -            if (c == 0) {
    -                reason = "null character not allowed @" + i;
    -                break;
    -            } else if (c == '/') {
    -                reason = "'/' not allowed @" + i;
    -                break;
    -            } else if (c > '\u0000' && c < '\u001f'
    -                    || c > '\u007f' && c < '\u009F'
    -                    || c > '\ud800' && c < '\uf8ff'
    -                    || c > '\ufff0' && c < '\uffff') {
    -                reason = "invalid charater @" + i;
    -                break;
    -            }
    +        if (isReservedStreamName(logName)) {
    +            throw new InvalidStreamNameException(logName, "Log Name is 
reserved");
             }
    -        if (null != reason) {
    -            throw new InvalidStreamNameException(nameOfStream, reason);
    +
    +        if (logName.charAt(0) == 47) {
    +            validatePathName(logName);
    +            return logName.substring(1);
    +        } else {
    +            validatePathName("/" + logName);
    +            return logName;
             }
    -        if (isReservedStreamName(nameOfStream)) {
    -            throw new InvalidStreamNameException(nameOfStream,
    -                    "Stream Name is reserved");
    +    }
    +
    +    private static void validatePathName(String logName) throws 
InvalidStreamNameException {
    +        if (logName == null) {
    +            throw new InvalidStreamNameException("Log name cannot be 
null");
    +        } else if (logName.length() == 0) {
    +            throw new InvalidStreamNameException("Log name length must be 
> 0");
    +        } else if (logName.charAt(0) != 47) {
    +            throw new InvalidStreamNameException("Log name must start with 
/ character");
    +        } else if (logName.length() != 1) {
    +            if (logName.charAt(logName.length() - 1) == 47) {
    +                throw new InvalidStreamNameException("Log name must not 
end with / character");
    +            } else {
    +                String reason = null;
    +                char lastc = 47;
    +                char[] chars = logName.toCharArray();
    +
    +                for (int i = 1; i < chars.length; ++i) {
    +                    char c = chars[i];
    +                    if (c == 0) {
    +                        reason = "null character not allowed @" + i;
    +                        break;
    +                    }
    +
    +                    if (c == '<' || c == '>') {
    +                        reason = "< or > specified @" + i;
    +                        break;
    +                    }
    +
    +                    if (c == ' ') {
    --- End diff --
    
    Is it needed other empty char like  HT, VT, CR, NL('\t',  '\r', '\n', 
'\x0b') ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to