Skip to content

Properties read from traditional application.properties files are not trimmed #4106

Closed

Description

@brenuart

The property values read from traditional application.properties configuration files are not trimmed. This can lead to undesired/strange behaviours at runtime:

  • @ConditionalOnProperty annotation perform a simple equals between the expected and received value (without type conversion). A property value set to 'true ' (notice the space at the end) is likely to fail the condition
  • developers must/should trim the injected string values themselves

Not trimming values out of properties files is error prone (you can't blame a user if they forgot a blank at the end of the line - they don't see it). It may be acceptable for XML files however: value is between start/end markers so the blank is visible.

Proposition is to update the PropertiesPropertySourceLoader so it automatically trims values read from .properties files.

Activity

  1. changed the title [-]Property values read from traditional application.properties files are not trimmed[/-] [+]Properties read from traditional application.properties files are not trimmed[/+] on Oct 8, 2015
  2. added
    status: waiting-for-triage
    on Nov 30, 2015
  3. added
    for: team-attention
    and removed
    status: waiting-for-triage
    on Dec 21, 2015
  4. self-assigned this
    on Jan 20, 2016
  5. wilkinsona commented on Jan 20, 2016

    @wilkinsona
    Member

    We've discussed this and decided that there's no way that we can safely trim properties as we have no way of knowing whether or not any trailing whitespace was intentional.

    If you have a problem where developers are leaving trailing whitespace in a properties file and you know that you never want such trailing whitespace, I would recommend configuring your editor to remove it automatically.

  6. added
    status: declined
    and removed
    for: team-attention
    on Jan 20, 2016
  7. removed their assignment
    on Jan 20, 2016
  8. lunarcloud commented on Feb 5, 2018

    @lunarcloud

    At least add a warning!
    This ran us crazy trying to figure out why some people saw an error and others didn't, only to find out it was because of-what most editors show as-invisible characters!

  9. lunarcloud commented on Feb 5, 2018

    @lunarcloud

    Nevermind. My issue was with the logging properties reader, not the generic property reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declined

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions