Skip to content

Use Locale.ROOT when lowercasing hardcoded description strings (#364) - #741

Open
munzzyy wants to merge 1 commit into
drewnoakes:mainfrom
munzzyy:fix/turkish-locale-lowercase-364
Open

Use Locale.ROOT when lowercasing hardcoded description strings (#364)#741
munzzyy wants to merge 1 commit into
drewnoakes:mainfrom
munzzyy:fix/turkish-locale-lowercase-364

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 23, 2026

Copy link
Copy Markdown

Fixes #364.

ExifDescriptorBase and GpsDescriptor build unit strings like "300 dots per inch" by calling toLowerCase() 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, so Locale.ROOT is 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 ExifIFD0DescriptorTest that sets the default locale to Turkish, exercises getXResolutionDescription(), 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.

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".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calls to toLowerCase() break various behaviour for Turkish locale

1 participant