checkNodeid
This commit is contained in:
@@ -97,7 +97,7 @@ class AppConfig {
|
|||||||
private void init(AnyValue conf) {
|
private void init(AnyValue conf) {
|
||||||
this.config = conf;
|
this.config = conf;
|
||||||
this.name = checkName(config.getValue("name", ""));
|
this.name = checkName(config.getValue("name", ""));
|
||||||
this.nodeid = config.getValue("nodeid", String.valueOf(Math.abs(System.nanoTime())));
|
this.nodeid = checkNodeid(config.getValue("nodeid", String.valueOf(Math.abs(System.nanoTime()))));
|
||||||
this.configFromCache = "true".equals(config.getValue("[config-from-cache]"));
|
this.configFromCache = "true".equals(config.getValue("[config-from-cache]"));
|
||||||
//初始化classLoader、serverClassLoader
|
//初始化classLoader、serverClassLoader
|
||||||
this.initClassLoader();
|
this.initClassLoader();
|
||||||
@@ -419,18 +419,47 @@ class AppConfig {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String checkName(String name) {
|
private static String checkName(String name) {
|
||||||
if (name == null || name.isEmpty()) {
|
if (name == null || name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
for (char ch : name.toCharArray()) {
|
for (char ch : name.toCharArray()) {
|
||||||
if (!((ch >= '0' && ch <= '9') || ch == '_' || ch == '.' || ch == '-' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符
|
if (!((ch >= '0' && ch <= '9')
|
||||||
throw new RedkaleException("name only 0-9 a-z A-Z _ - . cannot begin 0-9");
|
|| (ch >= 'a' && ch <= 'z')
|
||||||
|
|| (ch >= 'A' && ch <= 'Z')
|
||||||
|
|| ch == '_'
|
||||||
|
|| ch == '.'
|
||||||
|
|| ch == '-')) { //不能含特殊字符
|
||||||
|
throw new RedkaleException("name only 0-9 a-z A-Z _ - .");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查node是否含特殊字符
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String checkNodeid(String nodeid) {
|
||||||
|
if (nodeid == null || nodeid.isEmpty()) {
|
||||||
|
return nodeid;
|
||||||
|
}
|
||||||
|
for (char ch : nodeid.toCharArray()) {
|
||||||
|
if (!((ch >= '0' && ch <= '9')
|
||||||
|
|| (ch >= 'a' && ch <= 'z')
|
||||||
|
|| (ch >= 'A' && ch <= 'Z')
|
||||||
|
|| ch == '_'
|
||||||
|
|| ch == '.'
|
||||||
|
|| ch == '-')) { //不能含特殊字符
|
||||||
|
throw new RedkaleException("nodeid only 0-9 a-z A-Z _ - .");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodeid;
|
||||||
|
}
|
||||||
|
|
||||||
private String getCanonicalPath(File file) {
|
private String getCanonicalPath(File file) {
|
||||||
try {
|
try {
|
||||||
return file.getCanonicalPath();
|
return file.getCanonicalPath();
|
||||||
|
|||||||
Reference in New Issue
Block a user