Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enclose system properties containing white space with quotation marks #1958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Paranoja
Copy link

@Paranoja Paranoja commented Mar 13, 2025

Summary

Fixes #1904

For Surefire and Filesafe plugins with <systemPropertyVariables /> containing properties with white space characters:

  • tab (U+0009)
  • line feed (U+000a)
  • carriage return (U+000d)
  • space (U+0020)

wrap values with double quotation marks (").

Details

I chose these four characters as an intersection of a set of characters, supported by XML, and std::isspace() functions.

Command line reference for java command states in Standard options for java

-Dproperty=value
Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example -Dfoo="foo bar").

(emphasis mine)

that values with spaces must be enclosed, however in section Using the JDK_JAVA_OPTIONS Launcher Environment Variable it states:

The content of the JDK_JAVA_OPTIONS environment variable is a list of arguments separated by white-space characters (as determined by isspace())

and std::isspace() provides this list:

  • space (0x20, ' ')
  • form feed (0x0c, '\f')
  • line feed (0x0a, '\n')
  • carriage return (0x0d, '\r')
  • horizontal tab (0x09, '\t')
  • vertical tab (0x0b, '\v')

While 000 [C0 Controls and Basic Latin, C1 Controls and Latin-1 Supplement] section of XML Entity Definitions for Characters (3rd Edition) specifies, which Unicode characters with code points between U+00000 and U+000FF are valid XML entities.

Manual testing if java preserves said whitespace when passed to it through command line with following test program:

package test;

import static java.util.stream.Collectors.joining;

public class SpaceTest {

	public static void main(String[] args) {
		System.getProperties().forEach((name, val) -> {
			if (((String) name).startsWith("prop.")) {
				System.out.append((String) name).println(':');
				System.out.println(((String) val).chars().mapToObj("%02X"::formatted).collect(joining(" ", "\t[", "]")));
			}
		});
	}

}

have shown following behavior on Fedora 41 and OpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7):

java -p ${ws}/test/bin -Dprop.whitespaces="$(printf "{\t\n\v\f\r }")" -m test/test.SpaceTest

and output:

prop.whitespaces:
        [7B 09 0A 0B 0C 0D 20 7D]

@Paranoja Paranoja force-pushed the issue-1904-quote-system-properties-with-spaces branch from e5389e4 to c7e442b Compare March 23, 2025 17:19
@Paranoja Paranoja force-pushed the issue-1904-quote-system-properties-with-spaces branch from c7e442b to bd4ebe5 Compare March 23, 2025 21:23
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.

Surefire configuration of properties with spaces in values constructs incorrect Eclipse configuration
1 participant