This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 480e900b86e3b153420016988e3667cff23622b8 Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Fri May 24 23:18:26 2024 +0200 JSPWIKI-1186: Windows, install.jsp double escapes the jspwiki.workDir and nothing else --- .../main/java/org/apache/wiki/ui/Installer.java | 42 +++++++++++++++------- jspwiki-war/src/main/webapp/Install.jsp | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/Installer.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/Installer.java index 570d9722e..ac9b439de 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/Installer.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/Installer.java @@ -156,10 +156,8 @@ public class Installer { * @return the string */ public String getPropertiesList() { - final String result; final Set< String > keys = m_props.stringPropertyNames(); - result = keys.stream().map(key -> key + " = " + m_props.getProperty(key) + "\n").collect(Collectors.joining()); - return result; + return keys.stream().map( key -> key + " = " + m_props.getProperty( key ) + "\n" ).collect( Collectors.joining() ); } public String getPropertiesPath() { @@ -183,16 +181,14 @@ public class Installer { String nullValue = m_props.getProperty( APP_NAME, rb.getString( "install.installer.default.appname" ) ); parseProperty( APP_NAME, nullValue ); - // Get/sanitize page directory - nullValue = m_props.getProperty( PAGE_DIR, rb.getString( "install.installer.default.pagedir" ) ); - parseProperty( PAGE_DIR, nullValue ); - sanitizePath( PAGE_DIR ); - - // Get/sanitize work directory + // Get work directory nullValue = m_props.getProperty( WORK_DIR, TMP_DIR ); parseProperty( WORK_DIR, nullValue ); - sanitizePath( WORK_DIR ); - + + // Get page directory + nullValue = m_props.getProperty( PAGE_DIR, m_props.getProperty( WORK_DIR, TMP_DIR ) + File.separatorChar + "data" ); + parseProperty( PAGE_DIR, nullValue ); + // Set a few more default properties, for easy setup m_props.setProperty( STORAGE_DIR, m_props.getProperty( PAGE_DIR ) ); m_props.setProperty( PageManager.PROP_PAGEPROVIDER, "VersioningFileProvider" ); @@ -216,11 +212,15 @@ public class Installer { final ResourceBundle rb = ResourceBundle.getBundle( InternationalizationManager.CORE_BUNDLE, m_session.getLocale() ); m_session.clearMessages( INSTALL_ERROR ); parseProperties(); + // sanitize pages, attachments and work directories + sanitizePath( PAGE_DIR ); + sanitizePath( STORAGE_DIR ); + sanitizePath( WORK_DIR ); validateNotNull( PAGE_DIR, rb.getString( "install.installer.validate.pagedir" ) ); validateNotNull( APP_NAME, rb.getString( "install.installer.validate.appname" ) ); validateNotNull( WORK_DIR, rb.getString( "install.installer.validate.workdir" ) ); - if ( m_session.getMessages( INSTALL_ERROR ).length == 0 ) { + if( m_session.getMessages( INSTALL_ERROR ).length == 0 ) { m_validated = true; } return m_validated; @@ -251,6 +251,24 @@ public class Installer { s = s.trim(); m_props.put( key, s ); } + + public void restoreUserValues() { + desanitizePath( PAGE_DIR ); + desanitizePath( STORAGE_DIR ); + desanitizePath( WORK_DIR ); + } + + /** + * Simply removes sanitizations so values can be shown back to the user as they were entered + * + * @param key the key of the property to sanitize + */ + private void desanitizePath( final String key ) { + String s = m_props.getProperty( key ); + s = TextUtil.replaceString(s, "\\\\", "\\" ); + s = s.trim(); + m_props.put( key, s ); + } private void validateNotNull( final String key, final String message ) { final String value = m_props.getProperty( key ); diff --git a/jspwiki-war/src/main/webapp/Install.jsp b/jspwiki-war/src/main/webapp/Install.jsp index ee34fbeb0..0160d63a7 100644 --- a/jspwiki-war/src/main/webapp/Install.jsp +++ b/jspwiki-war/src/main/webapp/Install.jsp @@ -59,6 +59,7 @@ if( request.getParameter("submit") != null ) { installer.saveProperties(); password = installer.createAdministrator(); + installer.restoreUserValues(); if ( password != null ) { Object[] args = { Installer.ADMIN_ID, password, Installer.ADMIN_GROUP };
