This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 194418
Collapse All | Expand All

(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java (-4 / +10 lines)
Lines 54-59 Link Here
54
import java.util.Iterator;
54
import java.util.Iterator;
55
import java.util.Map;
55
import java.util.Map;
56
import java.util.Set;
56
import java.util.Set;
57
import java.util.logging.Level;
58
import java.util.logging.Logger;
57
import org.netbeans.modules.masterfs.ProvidedExtensionsProxy;
59
import org.netbeans.modules.masterfs.ProvidedExtensionsProxy;
58
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj;
60
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj;
59
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObjectFactory;
61
import org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObjectFactory;
Lines 72-77 Link Here
72
 * @author Radek Matous
74
 * @author Radek Matous
73
 */
75
 */
74
public final class FileBasedFileSystem extends FileSystem {
76
public final class FileBasedFileSystem extends FileSystem {
77
    private static final Logger LOG = Logger.getLogger(FileBasedFileSystem.class.getName());
75
    private static FileBasedFileSystem INSTANCE = new FileBasedFileSystem();
78
    private static FileBasedFileSystem INSTANCE = new FileBasedFileSystem();
76
    transient private RootObj<? extends FileObject> root;
79
    transient private RootObj<? extends FileObject> root;
77
    transient private final StatusImpl status = new StatusImpl();
80
    transient private final StatusImpl status = new StatusImpl();
Lines 200-212 Link Here
200
            }
203
            }
201
        }  else {
204
        }  else {
202
            name = (name.startsWith("/")) ? name : ("/"+name);    
205
            name = (name.startsWith("/")) ? name : ("/"+name);    
203
        }             
206
        }               
207
        File f = new File(name);
204
        if (name.contains("..")) {
208
        if (name.contains("..")) {
205
            if (("/" + name + "/").contains("/../")) {
209
            try {
206
                return null;
210
                f = f.getCanonicalFile();
211
            } catch (IOException ex) {
212
                LOG.log(Level.WARNING, "Cannot canonicalize " + f, ex);
207
            }
213
            }
208
        }
214
        }
209
        return getFileObject(new File(name));
215
        return getFileObject(f);
210
    }
216
    }
211
217
212
    @Override
218
    @Override
(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObj.java (-5 / +8 lines)
Lines 106-120 Link Here
106
            // #47885 - relative path must not contain back slashes
106
            // #47885 - relative path must not contain back slashes
107
            return null;
107
            return null;
108
        }
108
        }
109
        if (relativePath.contains("..")) {
110
            if (("/" + relativePath + "/").contains("/../")) {
111
                return null;
112
            }
113
        }
114
        if (relativePath.startsWith("/")) {
109
        if (relativePath.startsWith("/")) {
115
            relativePath = relativePath.substring(1);
110
            relativePath = relativePath.substring(1);
116
        }
111
        }
117
        File file = new File(getFileName().getFile(), relativePath);
112
        File file = new File(getFileName().getFile(), relativePath);
113
        if (relativePath.contains("..")) {
114
            try {
115
                file = file.getCanonicalFile();
116
            } catch (IOException ex) {
117
                LOG.log(Level.WARNING, "Cannot canonicalize " + file, ex);
118
            }
119
        }
120
        
118
        FileObjectFactory factory = getFactory();
121
        FileObjectFactory factory = getFactory();
119
        return factory.getValidFileObject(file, FileObjectFactory.Caller.GetFileObject);
122
        return factory.getValidFileObject(file, FileObjectFactory.Caller.GetFileObject);
120
    }
123
    }
(-)4a6cfcd35eb7 (+88 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.masterfs.filebasedfs.utils;
44
45
import java.io.File;
46
import org.netbeans.junit.NbTestCase;
47
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileUtil;
49
50
public class FileUtilParentTest extends NbTestCase {
51
52
    public FileUtilParentTest(String testName) {
53
        super(testName);
54
    }
55
56
    public void testNorm() throws Exception {
57
        File root = getWorkDir();
58
        // create dir1 
59
        File dir1 = new File(root, "d1");
60
        dir1.mkdirs();
61
        FileObject dirFO1 = FileUtil.toFileObject(dir1);
62
        assertNotNull(dirFO1);
63
        // create dir2
64
        File dir2 = new File(root, "d2");
65
        dir2.mkdirs();
66
        FileObject dirFO2 = FileUtil.toFileObject(dir2);
67
        assertNotNull(dirFO2);
68
69
        // create child in dir2
70
        File file = new File(dir2, "child");
71
        file.createNewFile();
72
        FileObject fo = FileUtil.toFileObject(file);
73
74
        // find dir2 by its relative path "../dir2"
75
        FileObject foundDirFO2 = dirFO1.getFileObject("../" + dirFO2.getNameExt());
76
        assertNotNull(foundDirFO2);
77
78
        assertParent(dirFO2, fo);
79
        assertParent(foundDirFO2, fo);
80
    }
81
82
    private void assertParent(FileObject parent, FileObject fo) {
83
        System.err.printf("isParentOf %s %s ? %b\n", parent.getPath(),
84
                fo.getPath(), FileUtil.isParentOf(parent, fo));
85
        assertTrue("FileObject " + parent + " should be parent of " + fo,
86
                FileUtil.isParentOf(parent, fo));
87
    }
88
}
(-)a/openide.filesystems/apichanges.xml (+18 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="to.parent">
53
            <api name="filesystems"/>
54
            <summary>FileObject.getFileObject accepts ".."</summary>
55
            <version major="7" minor="45"/>
56
            <date day="27" month="1" year="2011"/>
57
            <author login="jtulach"/>
58
            <compatibility addition="yes"/>
59
            <description>
60
                <p>
61
                    Semantic of 
62
                    <a href="@TOP@/org/openide/filesystems/FileObject.html#getFileObject(java.lang.String)">
63
                    getFileObject
64
                    </a> method has been clarified to accept "..".
65
                </p>
66
            </description>
67
            <class package="org.openide.filesystems" name="FileObject"/>
68
            <issue number="194418"/>
69
        </change>
52
        <change id="attribute.methodvalue">
70
        <change id="attribute.methodvalue">
53
            <api name="filesystems"/>
71
            <api name="filesystems"/>
54
            <summary>setAttribute("methodvalue:attrname", method) and "newvalue:"</summary>
72
            <summary>setAttribute("methodvalue:attrname", method) and "newvalue:"</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 7.44
5
OpenIDE-Module-Specification-Version: 7.45
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/AbstractFolder.java (-2 / +6 lines)
Lines 280-287 Link Here
280
                // than in getChild, than it is not called
280
                // than in getChild, than it is not called
281
                // so often.
281
                // so often.
282
                fo.check();
282
                fo.check();
283
283
                final String next = en.nextElement();
284
                fo = fo.getChild(en.nextElement());
284
                if ("..".equals(next)) {
285
                    fo = (AbstractFolder)fo.getParent();
286
                } else {
287
                    fo = fo.getChild(next);
288
                }
285
            }
289
            }
286
        }
290
        }
287
291
(-)a/openide.filesystems/src/org/openide/filesystems/FileObject.java (-1 / +8 lines)
Lines 836-841 Link Here
836
836
837
    /** Retrieve file or folder relative to a current folder, with a given relative path.
837
    /** Retrieve file or folder relative to a current folder, with a given relative path.
838
    * <em>Note</em> that neither file nor folder is created on disk. This method isn't final since revision 1.93.
838
    * <em>Note</em> that neither file nor folder is created on disk. This method isn't final since revision 1.93.
839
    * Since 7.45 common implementations of this method 
840
    * accept also ".." which is interpreted as a reference to parent.
841
    * 
839
    * @param relativePath is just basename of the file or (since 4.16) the relative path delimited by '/'
842
    * @param relativePath is just basename of the file or (since 4.16) the relative path delimited by '/'
840
    * @return the object representing this file or <CODE>null</CODE> if the file
843
    * @return the object representing this file or <CODE>null</CODE> if the file
841
    *   or folder does not exist
844
    *   or folder does not exist
Lines 855-861 Link Here
855
        }
858
        }
856
        while ((myObj != null) && st.hasMoreTokens()) {
859
        while ((myObj != null) && st.hasMoreTokens()) {
857
            String nameExt = st.nextToken();
860
            String nameExt = st.nextToken();
858
            myObj = myObj.getFileObject(nameExt, null);
861
            if (nameExt.equals("..")) { // NOI18N
862
                myObj = myObj.getParent();
863
            } else {
864
                myObj = myObj.getFileObject(nameExt, null);
865
            }
859
        }
866
        }
860
867
861
        return myObj;
868
        return myObj;
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java (-5 / +5 lines)
Lines 720-726 Link Here
720
        FileObject fold2 = getTestFolder1(fold1);
720
        FileObject fold2 = getTestFolder1(fold1);
721
        
721
        
722
        assertEquals("Is parent", fold1, fold2.getParent());
722
        assertEquals("Is parent", fold1, fold2.getParent());
723
        assertEquals("No .. can be used", null, fold2.getFileObject(".."));
723
        assertEquals(".. goes to parent", fold1, fold2.getFileObject(".."));
724
    }
724
    }
725
725
726
    public void  testFindResourceWithDots() throws Exception {
726
    public void  testFindResourceWithDots() throws Exception {
Lines 733-740 Link Here
733
        for (String s : arr) {
733
        for (String s : arr) {
734
            sb.append(s).append("/../").append(s).append('/');
734
            sb.append(s).append("/../").append(s).append('/');
735
        }
735
        }
736
        assertNull(
736
        assertEquals(
737
            "No .. in findResource allowed", 
737
            "Properly found", fold2,
738
            fold2.getFileSystem().findResource(sb.toString())
738
            fold2.getFileSystem().findResource(sb.toString())
739
        );
739
        );
740
    }
740
    }
Lines 821-828 Link Here
821
        FileObject r2 = fo1.getParent().getFileObject("../x/y.java");
821
        FileObject r2 = fo1.getParent().getFileObject("../x/y.java");
822
        FileObject r3 = fo1.getFileObject("../../x/y.java");
822
        FileObject r3 = fo1.getFileObject("../../x/y.java");
823
        assertEquals("y.java found without ..", fo2, r1);
823
        assertEquals("y.java found without ..", fo2, r1);
824
        assertNull("y.java not found with ..", r2);
824
        assertEquals("y.java found with ..", fo2, r2);
825
        assertNull("y.java not found with ../..", r3);
825
        assertEquals("y.java found with ../..", fo2, r3);
826
    }
826
    }
827
827
828
    public void  testGetPath5() throws  IOException{
828
    public void  testGetPath5() throws  IOException{

Return to bug 194418