You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by GitBox <gi...@apache.org> on 2021/02/23 09:36:44 UTC
[GitHub] [tomee] rzo1 opened a new pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
rzo1 opened a new pull request #763:
URL: https://github.com/apache/tomee/pull/763
# What does this PR do?
- Adds unit tests to reproduce TOMEE-2968 (also affects 7.0.x and 7.1.x)
- Single opening curly braces are stripped away in property values as we treat them as suffix placeholders (even in the case, we did not have an opening curly brace). PR proposes a related fix.
# References
- https://issues.apache.org/jira/browse/TOMEE-2968
- https://markmail.org/message/vxmm7t5sl33zr4wq
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585731086
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
@rmannibucau
Wouldn't returning the `key` instead of `null` in `PropertiesLookup#lookup` breaking the `:-` syntax?
From my understanding, `:-` is used for some sort of inlined "if else", i.e. "if foo is not defined, use bar instead" - is this assumption correct? Or maybe I didn't understood the substition process for `:-` correctly? :)
For example:
- "${foo:-bar}" -> `bar` (in the original implementation (returning `null`); `foo` is undefined)
- "${foo:-bar}" -> `foo` (if we return the `key` instead of `null`, the second part via `:-` is not evaluated as we have a match for the given key (which is the key itself))
edit:
Might be necessary to chain two substitutors to handle `:-` cases properly, sth like 1st lookup via substitutor returning `null` (via `PropertiesLookup#lookup`), 2nd lookup via substitutor returning `key` (via an extended `PropertiesLookup#lookup`, which returns `key` instead of `null`). Chained lookup might be skipped, if no `:-` is contained in the original `raw` input. Would bring the fallback replacement into the substitutor and the special case for `:-` is still supported. wdyt?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784130369
if incomplete noop should be done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784061648
> Hi @rzo1 , why not just escaping the character (think it is with '$' IIRC)?
Thought about it - current code will simply replace the closing bracket (even if we escape it).
Escaping with **$** is only done for the opening version, so atm it boils down to PREFIX="${" and SUFFIX="}" to support property substitutions like "${foo}---${bar}".
The question is, if we should replace closing / opening brackets by empty string in the first place, if the suffix/prefix environment is not complete / closed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784237920
@rzo1 :+1: , if you fix the regression of the default interpolation (noValueFound test and nested cases) it is good for me.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784364672
I think, we need to discuss, which one is the expected behaviour for `$${foo}`:
1. `$${foo}` -> `$${foo}` (noop)
2. `$${foo}` ->`${foo}` (escaped sequence, no replacement of placeholder (as mentioned in the docs of `StrSubstitutor`))
3. `$${foo}` -> `foo`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585708625
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
Thx @rmannibucau for the follow up!
Yes - testing with `contains` is a simplification and neglects some weirdo cases... and yes: it would require char, position + offsets to properly test and replace the closing and opening brackets.
Thus, I like the idea of using `PropertiesLookup#lookup` and returning the key there. The parsing "magic" (char, position, offsets) is already done in the substitutor, so I guess fallbacking there is a good option.
I will take a look at it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784274948
@rzo1 doesnt `if(raw.startsWith(ESCAPE_SEQUENCE)) return decryptIfNeeded(raw, acceptCharArray);` skips too much? what about `$${foo} ${bar}`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585731086
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
@rmannibucau
Wouldn't returning the `key` instead of `null` in `PropertiesLookup#lookup` breaking the `:-` syntax?
From my understanding, `:-` is used for some sort of inlined "if else", i.e. "if foo is not defined, use bar instead" - is this assumption correct? Or maybe I didn't understood the substition process for `:-` correctly? :)
For example:
- "${foo:-bar}" -> `bar` (in the original implementation (returning `null`); `foo` is undefined)
- "${foo:-bar}" -> `foo` (if we return the `key` instead of `null`, the second part via `:-` is not evaluated as we have a match for the given key (which is the key itself))
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784051271
Hi @rzo1 , why not just escaping the character (think it is with '$' IIRC)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784364672
I think, we need to discuss, which one is the expected behaviour for `$${foo}`:
1. `$${foo}` -> `$${foo}` (noop)
2. `$${foo}` ->`${foo}` (escaped sequence, no replacement of placeholder (as mentioned in the docs of `StrSubstitutor`))
3. `$${foo}` -> `foo`
I guess, it is probably **2.** or **3.** - WDYT?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784364672
I think, we need to discuss, which one is the expected behaviour for `$${foo}`:
1. `$${foo}` -> `$${foo}` (noop)
2. `$${foo}` ->`${foo}` (escaped sequence, no replacement of placeholder (as mentioned in the docs of `StrSubstitutor`))
3. `$${foo}` -> `foo`
I guess, it is probably **2.** or **3.**
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 merged pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 merged pull request #763:
URL: https://github.com/apache/tomee/pull/763
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] cesarhernandezgt commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
cesarhernandezgt commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784381840
I think it will be 2. $${foo} ->${foo}
I'm catching up with this ticket.
As a side note, Jenkins Job was green, then a new build hanged the job so I cancel and after your upcoming push, I hope the status on the PR gets in sync.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784364672
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784241505
@rzo1 yes, this enables for simple configuration to use some default as override key (quite useful for hosts for example) but also to nested keys more readably than with defaults - and was from the time defaults were not supported) so `${${foo}.bar}` would evaluate foo.bar if foo is missing (else <foo value>.bar). Side note: if it helps, fork commons-lang3 code, openejb-core shoudln't depend on it anyway and code is quite small - https://github.com/apache/openwebbeans-meecrowave/blob/master/meecrowave-core/src/main/java/org/apache/meecrowave/lang/Substitutor.java.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784239645
> @rzo1 , if you fix the regression of the default interpolation (noValueFound test and nested cases) it is good for me.
To see, if I get you right:
In case, no key is defined, we should resolve to the name of the key rather than doing a noop, ie `${v}` should resolve to `v` if no key for `v` is defined?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] cesarhernandezgt commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
cesarhernandezgt commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-785388287
@rzo1 I retrigger the build here: https://ci-builds.apache.org/job/Tomee/job/pull-request/81/
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-785681250
@cesarhernandezgt Thanks - the build looks good now 🙃
edit: let's wait a few more days to see if we get additional feedback otherwise I will integrate it as is.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784277046
Hmm yes - you are right. Will fix it soon.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784132571
> if incomplete noop should be done
Agreed.
This "noop" behaviour is implemented in this PR.
Before: } was replaced regardless of complete or not.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585731086
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
@rmannibucau
Wouldn't returning the `key` instead of `null` in `PropertiesLookup#lookup` breaking the `:-` syntax?
From my understanding, `:-` is used for some sort of inlined "if else", i.e. "if foo is not defined, use bar instead" - is this assumption correct? Or maybe I didn't understood the substition process for `:-` correctly? :)
For example:
- "${foo:-bar}" -> `bar` (in the original implementation (returning `null`); `foo` is undefined)
- "${foo:-bar}" -> `foo` (if we return the `key` instead of `null`, the second part via `:-` is not evaluated as we have a match for the given key (which is the key itself))
edit:
Might be necessary to chain two substitutors to handle `:-` cases properly, sth like 1st lookup via substitutor returning `null` (via `PropertiesLookup#lookup`), 2nd lookup via substitutor returning `key` (via an extended `PropertiesLookup#lookup`, which returns `key` instead of `null`). Chained lookup might be skipped, if no `:-` is contained in the original `raw` input. Would bring the fallback replacement into the substitutor and the special case for `:-` is still supported. wdyt?
edit-2:
Maybe for better understanding, what I was thinking about: https://github.com/rzo1/tomee/pull/3/files , which respects the `:-` syntax (not merged into this PR-branch yet, but to give an idea). Is this the right direction, @rmannibucau ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784388100
I think, that I have fixed the regression introduced while working on the escaped sequences.
The code should now reduce escaped placeholders according to **2.**
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784364672
I think, we need to discuss, which one is the expected behaviour for `$${foo}`:
1. `$${foo}` -> `$${foo}` (noop)
2. `$${foo}` ->` `${foo}` (escaped sequence, no replacement of placeholder (as mentioned in the docs of `StrSubstitutor`))
3. `$${foo}` -> `foo`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784132571
> if incomplete noop should be done
Agreed.
This behaviour is implemented in this PR.
Before: } was replaced regardless of complete or not.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585598827
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
I'm not sure you can implement this with "contains" checks (only t"here is none of these chars" test can be reliable) since you need the presence or not of the char + the position between the present ones to have a reliable test otherwise you can fall back in the same issue you originall hit which is to call "replace" where it is not needed.
Test are missing all these weirdo cases but since it is more or less the one you hit I guess it can happen.
A probably trivial fix is to extend PropertiesLookup to handle the fallback replacement (instead of null it returns the key) and just always call the substitutor if there is at least start+end chars. Worse case the substitutor will already do nothing.
Wdyt?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784232901
> @rzo1 so maybe add a test mixing both with `${foo}}`, `$${{foo}}`, `${${bar}}`, `${$${bar}}` and so on, this is what this PR can wrongly handle (ie both at the same time and nested case).
Thanks - I added some more tests mixing different cases / types of placeholders including the escape mechanism such as `$$` to skip placeholder substitution.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rmannibucau commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784144567
@rzo1 so maybe add a test mixing both with `${foo}}`, `$${{foo}}`, `${${bar}}`, `${$${bar}}` and so on, this is what this PR can wrongly handle (ie both at the same time and nested case).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-785358703
@cesarhernandezgt Can we manually re-trigger the Jenkins build or does it a scheduled build. I think the failing tests are unrelated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585731086
##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
}
public static String simpleValue(final String raw) {
- if (raw == null) {
- return null;
- }
- if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
- }
-
- String value = SUBSTITUTOR.replace(raw);
- if (!value.equals(raw) && value.startsWith("java:")) {
- value = value.substring(5);
- }
- return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+ return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
}
public static Object simpleValueAsStringOrCharArray(final String raw) {
+ return simpleValueAsStringOrCharArray(raw, true);
+ }
+
+ private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
if (raw == null) {
return null;
}
if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
- return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+ return decryptIfNeeded(raw, acceptCharArray);
}
String value = SUBSTITUTOR.replace(raw);
+
if (!value.equals(raw) && value.startsWith("java:")) {
value = value.substring(5);
}
- return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+ // no key defined and no escape sequence found -> substitute to key instead
+ if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))
Review comment:
@rmannibucau
Wouldn't returning the `key` instead of `null` in `PropertiesLookup#lookup` breaking the `:-` syntax?
From my understanding, `:-` is used for some sort of inlined "if else", i.e. "if foo is not defined, use bar instead" ~~Is this assumption correct? Or maybe I didn't understood the substition process for `:-` correctly?~~ (found it in the docs)
For example:
- "${foo:-bar}" -> `bar` (in the original implementation (returning `null`); `foo` is undefined)
- "${foo:-bar}" -> `foo` (if we return the `key` instead of `null`, the second part via `:-` is not evaluated as we have a match for the given key (which is the key itself))
edit:
Might be necessary to chain two substitutors to handle `:-` cases properly, sth like 1st lookup via substitutor returning `null` (via `PropertiesLookup#lookup`), 2nd lookup via substitutor returning `key` (via an extended `PropertiesLookup#lookup`, which returns `key` instead of `null`). Chained lookup might be skipped, if no `:-` is contained in the original `raw` input. Would bring the fallback replacement into the substitutor and the special case for `:-` is still supported. wdyt?
edit-2:
~~Maybe for better understanding, what I was thinking about: https://github.com/rzo1/tomee/pull/3/files , which respects the `:-` syntax (not merged into this PR-branch yet, but to give an idea).~~ I updated the PR with the proposed changes using `PropertiesLookup`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-785681250
@cesarhernandezgt Thanks - the build looks good now 🙃
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 edited a comment on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 edited a comment on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784388100
I think, that I have fixed the regression introduced while working on the escaped sequences.
The code should now reduce escaped placeholders according to **2.**
Let's see, what the Jenkins Job will produce :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tomee] rzo1 commented on pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"
Posted by GitBox <gi...@apache.org>.
rzo1 commented on pull request #763:
URL: https://github.com/apache/tomee/pull/763#issuecomment-784267147
> @rzo1 yes, this enables for simple configuration to use some default as override key (quite useful for hosts for example) but also to nested keys more readably than with defaults - and was from the time defaults were not supported) so `${${foo}.bar}` would evaluate foo.bar if foo is missing (else .bar). Side note: if it helps, fork commons-lang3 code, openejb-core shoudln't depend on it anyway and code is quite small - https://github.com/apache/openwebbeans-meecrowave/blob/master/meecrowave-core/src/main/java/org/apache/meecrowave/lang/Substitutor.java.
Regression should be fixed now - at least, if I understood it correctly.
`openejb-core` has some more dependencies towards `lang3`
- org.apache.commons.lang3.StringUtils
- org.apache.commons.lang3.text.StrLookup;
- org.apache.commons.lang3.text.StrSubstitutor; (alternative: Substitutor from `text` - might be worth replacing it as it is deprecated...)
- org.apache.commons.lang3.builder.ToStringBuilder
- org.apache.commons.lang3.ClassUtils
- org.apache.commons.lang3.tuple.ImmutablePair
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org