8290047: (fs) FileSystem.getPathMatcher does not check for ":" at last index
Reviewed-by: naoto, rriggs, alanb, lancea
This commit is contained in:
parent
8d0d9eaa9c
commit
4040927d17
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -304,7 +304,8 @@ public abstract class FileSystem
|
||||
* <blockquote><pre>
|
||||
* <i>syntax</i><b>:</b><i>pattern</i>
|
||||
* </pre></blockquote>
|
||||
* where {@code ':'} stands for itself.
|
||||
* where <i>syntax</i> is the non-empty name of the syntax, <i>pattern</i>
|
||||
* is a possibly-empty pattern string, and {@code ':'} stands for itself.
|
||||
*
|
||||
* <p> A {@code FileSystem} implementation supports the "{@code glob}" and
|
||||
* "{@code regex}" syntaxes, and may support others. The value of the syntax
|
||||
|
@ -175,8 +175,8 @@ class JrtFileSystem extends FileSystem {
|
||||
@Override
|
||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||
int pos = syntaxAndInput.indexOf(':');
|
||||
if (pos <= 0 || pos == syntaxAndInput.length()) {
|
||||
throw new IllegalArgumentException("pos is " + pos);
|
||||
if (pos <= 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
String syntax = syntaxAndInput.substring(0, pos);
|
||||
String input = syntaxAndInput.substring(pos + 1);
|
||||
|
@ -281,7 +281,7 @@ abstract class UnixFileSystem
|
||||
@Override
|
||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||
int pos = syntaxAndInput.indexOf(':');
|
||||
if (pos <= 0 || pos == syntaxAndInput.length())
|
||||
if (pos <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
String syntax = syntaxAndInput.substring(0, pos);
|
||||
String input = syntaxAndInput.substring(pos+1);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -261,7 +261,7 @@ class WindowsFileSystem
|
||||
@Override
|
||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||
int pos = syntaxAndInput.indexOf(':');
|
||||
if (pos <= 0 || pos == syntaxAndInput.length())
|
||||
if (pos <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
String syntax = syntaxAndInput.substring(0, pos);
|
||||
String input = syntaxAndInput.substring(pos+1);
|
||||
|
@ -441,7 +441,7 @@ class ZipFileSystem extends FileSystem {
|
||||
@Override
|
||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||
int pos = syntaxAndInput.indexOf(':');
|
||||
if (pos <= 0 || pos == syntaxAndInput.length()) {
|
||||
if (pos <= 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
String syntax = syntaxAndInput.substring(0, pos);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4313887 6866397 8073445
|
||||
* @bug 4313887 6866397 8073445 8290047
|
||||
* @summary Unit test for java.nio.file.PathMatcher
|
||||
*/
|
||||
|
||||
@ -84,6 +84,7 @@ public class Basic {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// basic
|
||||
assertMatch("", "");
|
||||
assertMatch("foo.html", "foo.html");
|
||||
assertNotMatch("foo.html", "foo.htm");
|
||||
assertNotMatch("foo.html", "bar.html");
|
||||
@ -137,6 +138,13 @@ public class Basic {
|
||||
assertBadPattern("foo.html", "*{class,java"); // missing }
|
||||
assertBadPattern("foo.html", "*.{class,{.java}}"); // nested group
|
||||
assertBadPattern("foo.html", "*.html\\"); // nothing to escape
|
||||
try {
|
||||
FileSystems.getDefault().getPathMatcher(":glob");
|
||||
System.err.println("No IllegalArgumentException for \":glob\"");
|
||||
failures++;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out.println("IllegalArgumentException for \":glob\" OKAY");
|
||||
}
|
||||
|
||||
// platform specific
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,6 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8141521 8216553 8266291 8290047
|
||||
* @summary Basic test of jrt file system provider
|
||||
* @run testng Basic
|
||||
*/
|
||||
@ -774,5 +775,19 @@ public class Basic {
|
||||
Files.exists(m);
|
||||
assertTrue(wasDirectory == Files.isDirectory(p));
|
||||
}
|
||||
|
||||
@DataProvider(name = "badSyntaxAndPattern")
|
||||
private Object[][] badSyntaxAndPattern() {
|
||||
return new Object[][] {
|
||||
{ ":glob"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "badSyntaxAndPattern",
|
||||
expectedExceptions = IllegalArgumentException.class)
|
||||
public void badSyntaxAndPatternTest(String syntaxAndPattern) {
|
||||
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
PathMatcher pm = fs.getPathMatcher(syntaxAndPattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -29,7 +29,7 @@ import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.ProviderMismatchException;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
@ -42,7 +42,7 @@ import java.util.Map;
|
||||
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
|
||||
/**
|
||||
* @test
|
||||
* @bug 8038500 8040059 8150366 8150496 8147539
|
||||
* @bug 8038500 8040059 8150366 8150496 8147539 8290047
|
||||
* @summary Basic test for zip provider
|
||||
*
|
||||
* @modules jdk.zipfs
|
||||
@ -89,7 +89,7 @@ public class Basic {
|
||||
// Test: copy file from zip file to current (scratch) directory
|
||||
Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider");
|
||||
if (Files.exists(source)) {
|
||||
Path target = Paths.get(source.getFileName().toString());
|
||||
Path target = Path.of(source.getFileName().toString());
|
||||
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
try {
|
||||
long s1 = Files.readAttributes(source, BasicFileAttributes.class).size();
|
||||
@ -113,6 +113,19 @@ public class Basic {
|
||||
throw new RuntimeException("watch service is not supported");
|
||||
} catch (ProviderMismatchException x) { }
|
||||
|
||||
// Test: IllegalArgumentException
|
||||
try {
|
||||
PathMatcher pm = fs.getPathMatcher(":glob");
|
||||
throw new RuntimeException("IllegalArgumentException not thrown");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
try {
|
||||
PathMatcher pm = fs.getPathMatcher("glob:");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
iae.printStackTrace();
|
||||
throw new RuntimeException("Unexpected IllegalArgumentException");
|
||||
}
|
||||
|
||||
// Test: ClosedFileSystemException
|
||||
fs.close();
|
||||
if (fs.isOpen())
|
||||
|
Loading…
Reference in New Issue
Block a user