[
https://issues.apache.org/jira/browse/TOMEE-2968?focusedWorklogId=560089&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-560089
]
ASF GitHub Bot logged work on TOMEE-2968:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 02/Mar/21 18:54
Start Date: 02/Mar/21 18:54
Worklog Time Spent: 10m
Work Description: 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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 560089)
Time Spent: 5h 10m (was: 5h)
> Postgres connection error when a password contains "}"
> ------------------------------------------------------
>
> Key: TOMEE-2968
> URL: https://issues.apache.org/jira/browse/TOMEE-2968
> Project: TomEE
> Issue Type: Bug
> Components: TomEE Core Server
> Affects Versions: 7.0.5, 8.0.0-Final, 7.1.4, 8.0.6
> Environment: Windows 10
> Reporter: Alex Levin
> Assignee: Richard Zowalla
> Priority: Major
> Time Spent: 5h 10m
> Remaining Estimate: 0h
>
> If a password contains the "}" character (closing curly brace), the database
> connection cannot be established.
> My resources.xml:
> <Resource id="Postgres Databse" type="javax.sql.DataSource">
> jdbcDriver org.postgresql.Driver
> jdbcUrl jdbc:postgresql://localhost:5432/postgresdb
> username scott
> password tiger...}
> maxActive = 250
> </Resource>
> Error message in the log:
> 2021-02-02 15:55:45 WARN [main] SqlExceptionHelper:144 - SQL Error: 0,
> SQLState: 28P01
> 2021-02-02 15:55:45 ERROR [main] SqlExceptionHelper:146 - FATAL: password
> authentication failed for user "scott"
--
This message was sent by Atlassian Jira
(v8.3.4#803005)