Copilot commented on code in PR #189:
URL: https://github.com/apache/commons-codec/pull/189#discussion_r3645492213


##########
src/test/java/org/apache/commons/codec/language/NysiisTest.java:
##########
@@ -140,7 +140,8 @@ public void testDropBy() throws EncoderException {
                 new String[] { "JILES", "JAL" },
                 // violates 6: if the last two characters are AY, remove A
                 new String[] { "CARRAWAY", "CARY" },       // Original: CARAY
-                new String[] { "YAMADA", "YANAD" });
+                new String[] { "YAMADA", "YANAD" },
+                new String[] { "ASH", "A"});

Review Comment:
   The PR description mentions both “ASH” → “A” and “SSH” → “S” as failing 
cases, but the added regression only covers the `'A'` scenario. Add a second 
assertion for the analogous `'S'` case (e.g., `\"SSH\"` expecting `\"S\"`) to 
prevent regressions in the other path.



##########
src/main/java/org/apache/commons/codec/language/Nysiis.java:
##########
@@ -314,6 +315,12 @@ public String nysiis(String str) {
             if (lastChar == 'A') {
                 key.deleteCharAt(key.length() - 1);
             }
+
+            if (key.length() == 0) {
+                // We've removed the first character of the string. Likely 
because it was an S or A
+                // We should return at least the first character
+                key.append(firstChar);
+            }

Review Comment:
   The empty-key restoration runs only after the `lastChar == 'A'` deletion, 
but the final cleanup can also delete a solitary trailing `'S'` (the other 
documented case in the PR description). As written, a word that reduces to a 
single `'S'` can still become `\"\"`. Consider restructuring the cleanup so you 
never delete the last remaining character (e.g., guard deletions with 
`key.length() > 1` for both `'A'` and `'S'`), or move the `key.length() == 0` 
safeguard to run after all final deletions (including `'S'`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to