garydgregory commented on a change in pull request #71: VFS-444: corrected ResourceFileProvider uri/path processing. URL: https://github.com/apache/commons-vfs/pull/71#discussion_r318288099
########## File path: commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileNameParser.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.vfs2.provider.res; + +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.provider.local.GenericFileNameParser; + +/** + * Slightly modified filename parser for resource URIs. + */ +public class ResourceFileNameParser extends GenericFileNameParser { + + private static final ResourceFileNameParser INSTANCE = new ResourceFileNameParser(); + + /** + * retrieve a instance to this parser. + * + * @return the parser + */ + public static GenericFileNameParser getInstance() { + return INSTANCE; + } + + @Override + protected String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { + // Resource uri (as used by ClassLoader.getResource()) are assumed to be absolute despite + // lacking a leading '/'. In fact, a leading '/' prevents resolving to the resource. + + if (name.length() == 0 || name.charAt(0) == '/') { Review comment: You can just say `name.isEmpty()` here instead of `name.length() == 0`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
