-
Notifications
You must be signed in to change notification settings - Fork 277
[#7446] Handle special characters followed by digits in http-client-java's CodeNamer.getEnumMemberName #7448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…-client-java's CodeNamer.getEnumMemberName
@@ -94,6 +94,15 @@ public static String getEnumMemberName(String name) { | |||
return name; | |||
} | |||
|
|||
// Special handling for inputs that start with special characters followed by numbers | |||
if (name.length() > 1 && !Character.isLetterOrDigit(name.charAt(0)) && Character.isDigit(name.charAt(1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add name.length() >= 2
if that is more readable/less of an index out of bounds mind phrack
No changes needing a change description found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution Eric!
This was a bug in conversion logic and your fixed definitely improves upon it.
I've let a comment about what we do consistently on some slightly different input like #$100 Gift Card
.
BTW, let us know which tool you uses when you encounter this bug (so that we can schedule a release after the fix).
@@ -32,6 +32,12 @@ public void testEnumMemberName() { | |||
|
|||
Assertions.assertEquals("ONE_ZEROMINUTELY", CodeNamer.getEnumMemberName("_10minutely")); | |||
|
|||
Assertions.assertEquals("DOLLAR_SIGN_100_GIFT_CARD", CodeNamer.getEnumMemberName("$100 Gift Card")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, without the fix the output would be 100_GIFT_CARD
, which is not a valid var name in Java.
There is 2 concern from me, on the output.
_100 Gift Card
would outputONE_ZERO_ZERO_GIFT_CARD
, thus from existing logic, it may be more reasonable to output same for$100 Gift Card
(I know thisONE_ZERO_ZERO_GIFT_CARD
looks bad...)#$100 Gift Card
would still generate100_GIFT_CARD
I am of pretty weak opinion on item (1), but I would like to see if we had something consistent for item (2).
BTW, if one uses TypeSpec, one would have the option to explicitly write the name of the enum, thus avoid this logic to infer the var name.
https://typespec.io/docs/language-basics/enums/#assigning-values-to-enums
No description provided.