Merge pull request #1945 from zkzlx/master

fixed - all unicode encoding , exclude base latin letter.
pull/1919/head^2
TheoneFx 4 years ago committed by GitHub
commit 4c75ef9197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,7 @@ package com.alibaba.cloud.nacos.utils;
*/
public final class NacosConfigUtils {
private NacosConfigUtils(){
private NacosConfigUtils() {
}
/**
@ -33,16 +33,26 @@ public final class NacosConfigUtils {
StringBuilder sb = new StringBuilder();
char[] chars = configValue.toCharArray();
for (char aChar : chars) {
if (isChinese(aChar)) {
sb.append("\\u").append(Integer.toHexString(aChar));
if (isBaseLetter(aChar)) {
sb.append(aChar);
}
else {
sb.append(aChar);
sb.append(String.format("\\u%04x", (int) aChar));
}
}
return sb.toString();
}
/**
* char is base latin or whitespace?
* @param ch a character
* @return true or false
*/
public static boolean isBaseLetter(char ch) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(ch);
return ub == Character.UnicodeBlock.BASIC_LATIN || Character.isWhitespace(ch);
}
/**
* char is chinese?
* @param c a character

Loading…
Cancel
Save