brigadier icon indicating copy to clipboard operation
brigadier copied to clipboard

Use Locale.ROOT for case folding

Open Pr0methean opened this issue 6 years ago • 8 comments

String.toLowerCase gives different results depending on the server JVM's default locale (see http://lotusnotus.com/lotusnotus_en.nsf/dx/dotless-i-tolowercase-and-touppercase-functions-use-responsibly.htm), so for example "KICK" wouldn't become "kick" if the server locale was Turkish. Explicitly using English case folding makes the behavior consistent regardless of server locale.

This PR also converts literal to lowercase in the constructor, rather than having to do it again every time listSuggestions is called, and makes the match in parse(StringReader) on line 56 case-insensitive.

Pr0methean avatar May 02 '19 04:05 Pr0methean

Good idea, though if I recall correctly the main Minecraft codebase uses Locale.ROOT instead of Locale.ENGLISH for this purpose.

Pokechu22 avatar May 02 '19 04:05 Pokechu22

CLA assistant check
All CLA requirements met.

msftclas avatar May 04 '19 18:05 msftclas

Yeah, I ran grep over the code to check for other uses of toLowerCase, toUpperCase and equalsIgnoreCase.

Pr0methean avatar May 05 '19 16:05 Pr0methean

I don't think it's ok to convert literal to lowercase in the constructor, because not all literals in Minecraft are lowercased, e.g. literal announceAdvancements in command /gamerule.

SPGoding avatar Jul 21 '19 15:07 SPGoding

@SPGoding Those literals aren't case-sensitive anyway, so the only place where it makes a difference is in the autocomplete.

Pr0methean avatar Jul 23 '19 14:07 Pr0methean

It's 1.16 update time, @Dinnerbone please reconsider looking into this (given fry is looking into DFU fixes).

liach avatar Jan 23 '20 18:01 liach

This is now superseded by #86

liach avatar Mar 23 '21 13:03 liach

This is now superseded by #86

The only difference seems to be that this pull request also changes it so literals are parsed case-sensitively here, though that might be an undesired behavior change?

Marcono1234 avatar May 04 '21 01:05 Marcono1234