Fixes OutputFileSetOnDirectory for non-canonical files. Bug: issue 8500 Change-Id: I991e306dd53ba909bc46f6372d45faf027b8385e
diff --git a/dev/core/src/com/google/gwt/dev/util/OutputFileSetOnDirectory.java b/dev/core/src/com/google/gwt/dev/util/OutputFileSetOnDirectory.java index 7fbf183..fc9b195 100644 --- a/dev/core/src/com/google/gwt/dev/util/OutputFileSetOnDirectory.java +++ b/dev/core/src/com/google/gwt/dev/util/OutputFileSetOnDirectory.java
@@ -1,12 +1,12 @@ /* * Copyright 2009 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -84,11 +84,7 @@ } } - private File pathToFile(String path) { - File file = dir; - for (String part : (prefix + path).split("/")) { - file = new File(file, part); - } - return file; + private File pathToFile(String path) throws IOException { + return new File(dir, prefix + path).getCanonicalFile(); } }
diff --git a/dev/core/test/com/google/gwt/dev/util/OutputFileSetOnDirectoryTest.java b/dev/core/test/com/google/gwt/dev/util/OutputFileSetOnDirectoryTest.java new file mode 100644 index 0000000..9aa7fbd --- /dev/null +++ b/dev/core/test/com/google/gwt/dev/util/OutputFileSetOnDirectoryTest.java
@@ -0,0 +1,49 @@ +/* + * Copyright 2014 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev.util; + +import com.google.gwt.util.tools.Utility; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; + +/** + * Tests for {@link OutputFileSetOnDirectory} + */ +public class OutputFileSetOnDirectoryTest extends TestCase { + + public void testCreateNewOutputStream() throws IOException { + File work = Utility.makeTemporaryDirectory(null, "outputfileset"); + try { + + OutputFileSetOnDirectory output = new OutputFileSetOnDirectory(work, "test/"); + int tstamp = OutputFileSet.TIMESTAMP_UNAVAILABLE; + + output.createNewOutputStream("path/to/file", tstamp).close(); + assertTrue(new File(work, "test/path/to/file").exists()); + + output.createNewOutputStream("path/../to/file", tstamp).close(); + assertTrue(new File(work, "test/to/file").exists()); + + output.createNewOutputStream("/../path/../to/./file", tstamp).close(); + assertTrue(new File(work, "to/file").exists()); + + } finally { + Util.recursiveDelete(work, false); + } + } + +}