[ 
https://issues.apache.org/jira/browse/LOG4J2-3568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17575800#comment-17575800
 ] 

Gary D. Gregory commented on LOG4J2-3568:
-----------------------------------------

A special case for space is not good enough because it ignores other characters 
that need to be URL encoded :-(

> ResolverUtil fails to extractPath for custom plugins in jar, if there are 
> blanks in the path
> --------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3568
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3568
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configuration
>    Affects Versions: 2.17.2
>         Environment: Windows 10
> Windows Server 2019
>            Reporter: Sven Seelig
>            Priority: Major
>
> We are using plugins in our config, e.g.:
> {noformat}
> "configuration": {
>   "name": "MyAppLog4JConfig",
>   "packages": "de.mycompany.myapp.adapter.log4j.plugin",
>   "properties": {
> ...
>   "appenders": {
> ...
>     "MyAppConsole": {
>       "name": "MyApp-Console-Appender",
>       "PatternLayout": {
>         "pattern": "${sysPatternlayout}",
>         "charset": "UTF-8"
>       }
>  {noformat}
> Everything works fine until the installation path of our application contains 
> one or more blanks, e.g. "C:\Program Files\MyApp_13.0.1". 
>  
> The plugin classes and the log4j2.json are delivered within jar files 
> (different jar files, same folder). The config-file itself is found and read. 
> We are accessing the context in a standard way:
>  
> {code:java}
> LoggerContext log4j2LoggerContext = 
> (org.apache.logging.log4j.core.LoggerContext) 
> org.apache.logging.log4j.LogManager.getContext(true);
> {code}
>  
> While trying to extract the path to our custom plugins, the PluginManager 
> lands here: 
> org.apache.logging.log4j.core.config.plugins.util.ResolverUtil#extractPath 
> {code:java}
> String extractPath(final URL url) throws UnsupportedEncodingException, 
> URISyntaxException {
>     String urlPath = url.getPath(); // same as getFile but without the Query 
> portion
> [...]
>     // For jar: URLs, the path part starts with "file:"
>     if (urlPath.startsWith("file:")) {
>         urlPath = urlPath.substring(5);
>     }
>     // If it was in a JAR, grab the path to the jar
>     final int bangIndex = urlPath.indexOf('!');
>     if (bangIndex > 0) {
>         urlPath = urlPath.substring(0, bangIndex);
>     }  
>  [...]     
> final String cleanPath = new URI(urlPath).getPath(); {code}
> Problem is, if the urlPath contains blank(s), the new URI(...) call will 
> throw an URISyntaxException and the plugins are not loaded.
> Simple solution would be an additional check and replacement of the blanks 
> with "%20".
> {code:java}
> if(urlPath.contains(" ")){
>     urlPath = urlPath.replace(" ", "%20");
> }
> final String cleanPath = new URI(urlPath).getPath(); {code}
> or
> {code:java}
> final String cleanPath = new URI(urlPath.replace(" ", "%20")).getPath(); 
> {code}
> We built the current release-2,x from the repo 
> ([https://gitbox.apache.org/repos/asf/logging-log4j2.git]), had the same 
> issue as before (2.17.2) but with this check added it works.
> As we can't run the maven build with tests (there seems to be a proxy issue 
> for the MongoDB Tests), we decided not to open a pull-request. Please let us 
> know, if you prefer a pull-request or if you need further information.
> (i) We are using the log4j-bridge at the moment, maybe this issue only shows 
> up when using this besides log4j2 core and api (i) 
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to