smallrye-config icon indicating copy to clipboard operation
smallrye-config copied to clipboard

Strange `$` escape or "too many lost `\`"

Open magicprinc opened this issue 1 year ago • 4 comments

$ character has special meaning only in front of { i.e: ${my.var.name}

If alone, $ is (must be) harmless.

But one has to escape this harmless $ very hard :-( Standalone $ eats too much escaping!

System.setProperty("test.key", " $ ");
assertEquals(" $ ", JProperties.config().getValue("test.key", String.class));// SmallRye Config
System.setProperty("test.key", " \\$ ");
assertEquals(" $ ", JProperties.config().getValue("test.key", String.class));
System.setProperty("test.key", " \\\\$ ");
assertEquals(" \\$ ", JProperties.config().getValue("test.key", String.class));

System.setProperty("test.key", " $$ ");
assertEquals(" $ ", JProperties.config().getValue("test.key", String.class));
System.setProperty("test.key", " \\$$ ");
assertEquals(" $$ ", JProperties.config().getValue("test.key", String.class));
System.setProperty("test.key", " \\\\$$ ");
assertEquals(" \\$$ ", JProperties.config().getValue("test.key", String.class));

Real world example: macros.key.freemarker.format=\\$\\{%s} Spring → "\$\{%s}" SmallRye → "$\{%s}"

See also https://github.com/smallrye/smallrye-config/issues/746 https://github.com/smallrye/smallrye-config/issues/1056

magicprinc avatar Sep 06 '24 16:09 magicprinc

@dmlloyd want to reply? :)

radcortez avatar Sep 12 '24 19:09 radcortez

It's more or less permanently broken until we can address this at a lower level. The primary lesson being "never add a syntax preprocessor to an established syntax without understanding that syntax fully".

It should probably be addressed in smallrye-common directly with an option flag to enable (yet another kind of) escaping using backslash, and then encoded directly into that grammar.

Additionally, all code which "senses" expressions by doing e.g. indexOf('$') or anything similar should be nuked from orbit.

dmlloyd avatar Sep 12 '24 19:09 dmlloyd

Quarkus uses SmallRye Config and has the same problem and no one complains? 😭

magicprinc avatar Sep 13 '24 10:09 magicprinc

It should probably be addressed in smallrye-common directly with an option flag to enable (yet another kind of) escaping using backslash, and then encoded directly into that grammar.

I'll see what I can do.

radcortez avatar Sep 13 '24 10:09 radcortez