Skip to content

Non-ASCII characters are corrupted when importing properties content with the env: prefix #52647

Closed

Description

@Ludocius

SystemEnvironmentConfigDataResource turns the environment variable value into bytes with content.getBytes(StandardCharsets.UTF_8), but then calls loader.load(name, resource, this.encoding) with encoding == null unless the [encoding=...] hint is used. OriginTrackedPropertiesLoader then decodes with its default ISO-8859-1, so any non-ASCII character in a .properties-style variable is corrupted.

Since the environment variable is already a String, there is no file encoding involved, and the bytes Spring Boot produces itself are always UTF-8.

Spring Boot 4.1.2

MY_CONF='greeting=Grüße' java -jar app.jar --spring.config.import=env:MY_CONF
environment.getProperty("greeting")  ->  "Grüße"      (expected "Grüße")

The same content imported as YAML (env:MY_CONF[.yaml]) is read correctly. Adding [encoding=utf-8] works around the problem, but users have no reason to expect they need it for an in-memory string.

Possible fix: in SystemEnvironmentConfigDataResource#load, default to the charset the content was encoded with:

private Charset getEncoding() {
	return (this.encoding != null) ? this.encoding : StandardCharsets.UTF_8;
}

I verified this end to end: I ran the packaged app as a separate process with the variable set and read the value over HTTP. With 4.1.2 the bytes are 47 72 c3 83 c2 bc .... With a locally built spring-boot jar including the change above, the result is Grüße (47 72 c3 bc c3 9f 65). The existing SystemEnvironmentConfigData* tests still pass. I'm happy to submit a PR with a test.

Activity

  1. added
    status: waiting-for-triage
    on Nov 7, 2026
  2. self-assigned this
    on Nov 11, 2026
  3. added
    type: bug
    and removed
    status: waiting-for-triage
    on Nov 12, 2026
  4. added this to the 4.1.3 milestone on Nov 12, 2026
  5. philwebb commented on Nov 12, 2026

    @philwebb
    Member

    We have the same issue with 4.0.x but it's unfortunately too hard to fix there so we'll target this one to 4.1+

  6. added a commit that references this issue on Nov 12, 2026
    f6ceb79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions