Author: oheger
Date: Sat Feb 3 08:19:15 2007
New Revision: 503227
URL: http://svn.apache.org/viewvc?view=rev&rev=503227
Log:
CONFIGURATION-252: ConfigurationUtils.getFile() now always checks first whether
the passed in file name is absolute.
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java?view=diff&rev=503227&r1=503226&r2=503227
==============================================================================
---
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
(original)
+++
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
Sat Feb 3 08:19:15 2007
@@ -595,7 +595,22 @@
* Tries to convert the specified base path and file name into a file
object.
* This method is called e.g. by the save() methods of file based
* configurations. The parameter strings can be relative files, absolute
- * files and URLs as well.
+ * files and URLs as well. This implementation checks first whether the
passed in
+ * file name is absolute. If this is the case, it is returned. Otherwise
+ * further checks are performed whether the base path and file name can be
+ * combined to a valid URL or a valid file name. <em>Note:</em> The test
+ * if the passed in file name is absolute is performed using
+ * <code>java.io.File.isAbsolute()</code>. If the file name starts with a
+ * slash, this method will return <b>true</b> on Unix, but <b>false</b> on
+ * Windows. So to ensure correct behavior for relative file names on all
+ * platforms you should never let relative paths start with a slash. E.g.
+ * in a configuration definition file do not use something like that:
+ * <pre>
+ * <properties fileName="/subdir/my.properties"/>
+ * </pre>
+ * Under Windows this path would be resolved relative to the configuration
+ * definition file. Under Unix this would be treated as an absolute path
+ * name.
*
* @param basePath the base path
* @param fileName the file name
@@ -603,6 +618,13 @@
*/
public static File getFile(String basePath, String fileName)
{
+ // Check if the file name is absolute
+ File f = new File(fileName);
+ if (f.isAbsolute())
+ {
+ return f;
+ }
+
// Check if URLs are involved
URL url;
try
Modified:
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java?view=diff&rev=503227&r1=503226&r2=503227
==============================================================================
---
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
(original)
+++
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
Sat Feb 3 08:19:15 2007
@@ -175,7 +175,7 @@
expected.add("value2");
ListAssert.assertEquals("'key2' property", expected,
conf2.getList("key2"));
}
-
+
public void testGetFile() throws Exception
{
File directory = new File("target");
@@ -186,6 +186,9 @@
assertEquals(reference,
ConfigurationUtils.getFile(directory.getAbsolutePath(), reference.getName()));
assertEquals(reference,
ConfigurationUtils.getFile(directory.toURL().toString(), reference.getName()));
assertEquals(reference, ConfigurationUtils.getFile("invalid",
reference.toURL().toString()));
+ assertEquals(reference, ConfigurationUtils.getFile(
+ "jar:file:/C:/myjar.jar!/my-config.xml/someprops.properties",
+ reference.getAbsolutePath()));
}
public void testLocateWithNullTCCL() throws Exception
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=503227&r1=503226&r2=503227
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Feb 3
08:19:15 2007
@@ -26,6 +26,12 @@
<action dev="oheger" type="add">
A pom for maven 2 was added.
</action>
+ <action dev="oheger" type="update" issue="CONFIGURATION-252">
+ ConfigurationUtils.getFile() now always checks first whether the passed
+ in file name is absolute. If it is, this file will be returned. This
+ prevents that on Unix under certain circumstances absolute file names
+ are interpreted as relative ones.
+ </action>
<action dev="oheger" type="update" issue="CONFIGURATION-251">
The dependency to xml-apis was changed to the version 1.0.b2. The so
far used version 2.0.2 is reported to be bogus.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]