Skip to content

Commit da50885

Browse files
committed
Fix possible StringIndexOutOfBoundException
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
1 parent 44e4c4d commit da50885

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,28 @@ public final String encode(String name) {
126126
// Preprocessing
127127
name = cleanName(name);
128128

129+
// Bulletproof if name becomes empty after cleanName(name)
130+
if (EMPTY.equalsIgnoreCase(name) || SPACE.equalsIgnoreCase(name) || name.length() == 0) {
131+
return EMPTY;
132+
}
133+
129134
// BEGIN: Actual encoding part of the algorithm...
130135
// 1. Delete all vowels unless the vowel begins the word
131136
name = removeVowels(name);
132137

138+
// Bulletproof if name becomes empty after removeVowels(name)
139+
if (EMPTY.equalsIgnoreCase(name) || SPACE.equalsIgnoreCase(name) || name.length() == 0) {
140+
return EMPTY;
141+
}
142+
133143
// 2. Remove second consonant from any double consonant
134144
name = removeDoubleConsonants(name);
135145

146+
// Bulletproof if name becomes empty after removeDoubleConsonants(name)
147+
if (EMPTY.equalsIgnoreCase(name) || SPACE.equalsIgnoreCase(name) || name.length() == 0) {
148+
return EMPTY;
149+
}
150+
136151
// 3. Reduce codex to 6 letters by joining the first 3 and last 3 letters
137152
name = getFirst3Last3(name);
138153

0 commit comments

Comments
 (0)