Use Locale.ROOT when lowercasing hardcoded description strings (#364) - #741
Open
munzzyy wants to merge 1 commit into
Open
Use Locale.ROOT when lowercasing hardcoded description strings (#364)#741munzzyy wants to merge 1 commit into
munzzyy wants to merge 1 commit into
Conversation
Resolution and GPS unit descriptions ("Inch", "cm", "kilometers", etc.)
are hardcoded ASCII, but the code lowercased them with the JVM's
default locale. Under a Turkish locale this turns "Inch" into "ınch"
(dotless i), corrupting the description text.
Pass Locale.ROOT to toLowerCase() at the affected call sites in
ExifDescriptorBase and GpsDescriptor so the conversion is independent
of the user's locale. Fixes drewnoakes#364.
Added a regression test that runs under a Turkish default locale and
checks the resolution description comes out as plain ASCII "inch".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #364.
ExifDescriptorBaseandGpsDescriptorbuild unit strings like "300 dots per inch" by callingtoLowerCase()on a hardcoded, ASCII description string ("Inch", "cm", "kilometers", "miles", "knots"). That call uses the JVM's default locale. Under a Turkish locale,"Inch".toLowerCase()produces "ınch" (dotless ı), because Turkish case rules treat 'I' differently than every other locale. Same problem for any user whose default locale is Turkish - the reported metadata comes out with corrupted words.This only touches the six
toLowerCase()calls that operate on these hardcoded description strings, not the wider locale/encoding discussion in the issue thread (MetadataContext, byte encoding, etc.). Those strings never need locale-sensitive casing since they're not user-facing translated text, soLocale.ROOTis the right fix: it makes the conversion always behave the same regardless of the runtime's default locale.Changed:
Source/com/drew/metadata/exif/ExifDescriptorBase.java:getXResolutionDescription(),getYResolutionDescription(),getFocalPlaneXResolutionDescription(),getFocalPlaneYResolutionDescription()Source/com/drew/metadata/exif/GpsDescriptor.java:getGpsDestDistanceDescription(),getGpsSpeedDescription()Added a test in
ExifIFD0DescriptorTestthat sets the default locale to Turkish, exercisesgetXResolutionDescription(), and asserts the result is "300 dots per inch" rather than "300 dots per ınch". Verified it fails against the current code and passes with the fix, and ran the full test suite (306 tests) with no other regressions.