package com.ctrip.framework.apollo.common.utils;

import com.ctrip.framework.apollo.core.utils.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Jason Song(song_s@ctrip.com)
 */
public class InputValidator {
  public static final String INVALID_CLUSTER_NAMESPACE_MESSAGE = "只允许输入数字，字母和符号 - _ .";
  public static final String INVALID_NAMESPACE_NAMESPACE_MESSAGE = "不允许以.json, .yml, .yaml, .xml, .properties结尾";
  public static final String CLUSTER_NAMESPACE_VALIDATOR = "[0-9a-zA-z_.-]+";
  public static final String APP_NAMESPACE_VALIDATOR = "[a-zA-z0-9._-]+(?<!\\.(json|yml|yaml|xml|properties))$";
  private static final Pattern CLUSTER_NAMESPACE_PATTERN =
      Pattern.compile(CLUSTER_NAMESPACE_VALIDATOR);
  private static final Pattern APP_NAMESPACE_PATTERN =
      Pattern.compile(APP_NAMESPACE_VALIDATOR);


  public static boolean isValidClusterNamespace(String input) {
    Matcher matcher = CLUSTER_NAMESPACE_PATTERN.matcher(input);
    return matcher.matches();
  }

  public static boolean isValidAppNamespace(String name){
    if (StringUtils.isEmpty(name)){
      return false;
    }
    return CLUSTER_NAMESPACE_PATTERN.matcher(name.toLowerCase()).matches() && APP_NAMESPACE_PATTERN.matcher(name).matches();
  }
}

@@ -516,17 +516,17 @@
 0-9a-zA-
-z
+Z
 _.-%5D+%22;%0A
@@ -587,17 +587,17 @@
  %22%5Ba-zA-
-z
+Z
 0-9._-%5D+
@@ -1190,22 +1190,8 @@
 name
-.toLowerCase()
 ).ma

fix regex error