Merge pull request #4081 from 18855532268/v5-dev

fix:添加判空处理
This commit is contained in:
Golden Looly 2025-09-19 20:33:09 +08:00 committed by GitHub
commit bde2472596
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -104,7 +104,7 @@ public class PinyinUtil {
* @return 汉字返回拼音非汉字原样返回 * @return 汉字返回拼音非汉字原样返回
*/ */
public static String getFirstLetter(String str, String separator) { public static String getFirstLetter(String str, String separator) {
return getEngine().getFirstLetter(str, separator); return (str == null) ? null : getEngine().getFirstLetter(str, separator);
} }
/** /**

View File

@ -22,4 +22,10 @@ public class PinyinUtilTest {
final String result = PinyinUtil.getFirstLetter("崞阳", ", "); final String result = PinyinUtil.getFirstLetter("崞阳", ", ");
assertEquals("g, y", result); assertEquals("g, y", result);
} }
@Test
public void getFirstLetterTest3(){
final String result = PinyinUtil.getFirstLetter(null, ", ");
assertNull(result);
}
} }