":" and "=" characters escaped when generating properties file #258

Closed
opened 2025-12-30 01:22:51 +01:00 by adam · 4 comments
Owner

Originally created by @Valentin-Rault on GitHub (Dec 17, 2024).

Context:
I am generating a .properties file but the characters ":" and "=" are being escaped.

Example:

class Default {
    project: String
    fixed url = "https://domain.name.com
}
token = read("env:TOKEN") // TOKEN is a string that can contain the mentioned characters

defaults = new Default {
    project = "some-project"
}

The generated default.properties file looks like this

token = some\=randomtokenreadfromtheenv
project = some-project
url = https\://domain.name.com

I am expecting the token and url to not escape the characters.

Originally created by @Valentin-Rault on GitHub (Dec 17, 2024). Context: I am generating a .properties file but the characters ":" and "=" are being escaped. Example: ``` class Default { project: String fixed url = "https://domain.name.com } token = read("env:TOKEN") // TOKEN is a string that can contain the mentioned characters defaults = new Default { project = "some-project" } ``` The generated default.properties file looks like this ``` token = some\=randomtokenreadfromtheenv project = some-project url = https\://domain.name.com ``` I am expecting the token and url to not escape the characters.
adam closed this issue 2025-12-30 01:22:51 +01:00
Author
Owner

@holzensp commented on GitHub (Dec 18, 2024):

Pkl's renderers always aim to render according to a format's standards. If you look at the documentation for java.util.Properties::store (here) it says:

The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.

And, indeed, if you load the generated .properties file, the result is as expected:

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Test {
  public static void main(String[] args) {
    Properties appProps = new Properties();
    try {
      appProps.load(new FileInputStream("/path/to/test.properties"));
      System.out.println(appProps);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

produces

{project=some-project, url=https://domain.name.com, token=some=randomtokenreadfromtheenv}

Why is it important for you that it does not escape?

@holzensp commented on GitHub (Dec 18, 2024): Pkl's renderers always aim to render according to a format's standards. If you look at the documentation for [`java.util.Properties::store` (here)](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Properties.html#store(java.io.Writer,java.lang.String)) it says: > The key and element characters `#`, `!`, `=`, and `:` are written with a preceding backslash to ensure that they are properly loaded. And, indeed, if you load the generated `.properties` file, the result is as expected: ``` import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class Test { public static void main(String[] args) { Properties appProps = new Properties(); try { appProps.load(new FileInputStream("/path/to/test.properties")); System.out.println(appProps); } catch (IOException e) { e.printStackTrace(); } } } ``` produces ``` {project=some-project, url=https://domain.name.com, token=some=randomtokenreadfromtheenv} ``` Why is it important for you that it does _not_ escape?
Author
Owner

@Valentin-Rault commented on GitHub (Dec 18, 2024):

I am attempting to generate multiple sentry.properties files for our CI as we have multiple projects. I might have been trying to fix an issue that isn't there by trying to not have it escape.
The generated sentry.properties file that was generated by their wizard does not escape those characters and therefore I was trying to achieve the same result when generating it with PKL.

I will have more insights after building my app with Xcode, there I will be able to see if the token and url are being loaded correctly.
I will post a message on this issue once this is done.

Thank you for the clarifying message.

@Valentin-Rault commented on GitHub (Dec 18, 2024): I am attempting to generate multiple sentry.properties files for our CI as we have multiple projects. I might have been trying to fix an issue that isn't there by trying to not have it escape. The generated sentry.properties file that was generated by their wizard does not escape those characters and therefore I was trying to achieve the same result when generating it with PKL. I will have more insights after building my app with Xcode, there I will be able to see if the token and url are being loaded correctly. I will post a message on this issue once this is done. Thank you for the clarifying message.
Author
Owner

@Valentin-Rault commented on GitHub (Dec 20, 2024):

Indeed it looks like the token and url are being loaded correctly. Thank you for the clarification

@Valentin-Rault commented on GitHub (Dec 20, 2024): Indeed it looks like the token and url are being loaded correctly. Thank you for the clarification
Author
Owner

@bioball commented on GitHub (Dec 23, 2024):

Closing this as resolved. Please let us know if there's any more questions here.

@bioball commented on GitHub (Dec 23, 2024): Closing this as resolved. Please let us know if there's any more questions here.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#258