Skip to content

Encoding of strings read from Recurly is sensitive to current locale #403

@glasser

Description

@glasser

Describe the bug

We have a customer whose company name is, say, UTF8 ț Test.
When we read this value via RecurlyClient.getAccount("foo").getCompanyName(), the name gets converted to UTF8 �� Test, if our program is running in a locale like LC_ALL=C on Linux.

Setting LC_ALL=C.UTF-8 or using -Dfile.encoding=UTF-8 fixes this, but since Recurly is always sending UTF-8, it would be great if you don't have to carefully run your app in this locale.

I believe the bug comes from this code in RecurlyClient.java:

    private String convertStreamToString(final java.io.InputStream is) {
        try {
            return new Scanner(is).useDelimiter("\\A").next();
        } catch (final NoSuchElementException e) {
            return "";
        }
    }

This Scanner constructor uses the platform charset instead of specifying UTF-8. Switching to the constructor that specifies the charset should help.

Your Environment

  • Which version of this library are you using?

0.34.0

  • Which version of java are you using?

zulu8.46.0.19-ca-jdk8.0.252-linux_x64

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions