mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
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
8 changed files with 52 additions and 15 deletions
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -304,7 +304,8 @@ public abstract class FileSystem
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* <i>syntax</i><b>:</b><i>pattern</i>
|
* <i>syntax</i><b>:</b><i>pattern</i>
|
||||||
* </pre></blockquote>
|
* </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
|
* <p> A {@code FileSystem} implementation supports the "{@code glob}" and
|
||||||
* "{@code regex}" syntaxes, and may support others. The value of the syntax
|
* "{@code regex}" syntaxes, and may support others. The value of the syntax
|
||||||
|
|
|
@ -175,8 +175,8 @@ class JrtFileSystem extends FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||||
int pos = syntaxAndInput.indexOf(':');
|
int pos = syntaxAndInput.indexOf(':');
|
||||||
if (pos <= 0 || pos == syntaxAndInput.length()) {
|
if (pos <= 0) {
|
||||||
throw new IllegalArgumentException("pos is " + pos);
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
String syntax = syntaxAndInput.substring(0, pos);
|
String syntax = syntaxAndInput.substring(0, pos);
|
||||||
String input = syntaxAndInput.substring(pos + 1);
|
String input = syntaxAndInput.substring(pos + 1);
|
||||||
|
|
|
@ -281,7 +281,7 @@ abstract class UnixFileSystem
|
||||||
@Override
|
@Override
|
||||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||||
int pos = syntaxAndInput.indexOf(':');
|
int pos = syntaxAndInput.indexOf(':');
|
||||||
if (pos <= 0 || pos == syntaxAndInput.length())
|
if (pos <= 0)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
String syntax = syntaxAndInput.substring(0, pos);
|
String syntax = syntaxAndInput.substring(0, pos);
|
||||||
String input = syntaxAndInput.substring(pos+1);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -261,7 +261,7 @@ class WindowsFileSystem
|
||||||
@Override
|
@Override
|
||||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||||
int pos = syntaxAndInput.indexOf(':');
|
int pos = syntaxAndInput.indexOf(':');
|
||||||
if (pos <= 0 || pos == syntaxAndInput.length())
|
if (pos <= 0)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
String syntax = syntaxAndInput.substring(0, pos);
|
String syntax = syntaxAndInput.substring(0, pos);
|
||||||
String input = syntaxAndInput.substring(pos+1);
|
String input = syntaxAndInput.substring(pos+1);
|
||||||
|
|
|
@ -441,7 +441,7 @@ class ZipFileSystem extends FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
public PathMatcher getPathMatcher(String syntaxAndInput) {
|
||||||
int pos = syntaxAndInput.indexOf(':');
|
int pos = syntaxAndInput.indexOf(':');
|
||||||
if (pos <= 0 || pos == syntaxAndInput.length()) {
|
if (pos <= 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
String syntax = syntaxAndInput.substring(0, pos);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4313887 6866397 8073445
|
* @bug 4313887 6866397 8073445 8290047
|
||||||
* @summary Unit test for java.nio.file.PathMatcher
|
* @summary Unit test for java.nio.file.PathMatcher
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ public class Basic {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// basic
|
// basic
|
||||||
|
assertMatch("", "");
|
||||||
assertMatch("foo.html", "foo.html");
|
assertMatch("foo.html", "foo.html");
|
||||||
assertNotMatch("foo.html", "foo.htm");
|
assertNotMatch("foo.html", "foo.htm");
|
||||||
assertNotMatch("foo.html", "bar.html");
|
assertNotMatch("foo.html", "bar.html");
|
||||||
|
@ -137,6 +138,13 @@ public class Basic {
|
||||||
assertBadPattern("foo.html", "*{class,java"); // missing }
|
assertBadPattern("foo.html", "*{class,java"); // missing }
|
||||||
assertBadPattern("foo.html", "*.{class,{.java}}"); // nested group
|
assertBadPattern("foo.html", "*.{class,{.java}}"); // nested group
|
||||||
assertBadPattern("foo.html", "*.html\\"); // nothing to escape
|
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
|
// platform specific
|
||||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 8141521 8216553 8266291 8290047
|
||||||
* @summary Basic test of jrt file system provider
|
* @summary Basic test of jrt file system provider
|
||||||
* @run testng Basic
|
* @run testng Basic
|
||||||
*/
|
*/
|
||||||
|
@ -774,5 +775,19 @@ public class Basic {
|
||||||
Files.exists(m);
|
Files.exists(m);
|
||||||
assertTrue(wasDirectory == Files.isDirectory(p));
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.PathMatcher;
|
||||||
import java.nio.file.ProviderMismatchException;
|
import java.nio.file.ProviderMismatchException;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
@ -42,7 +42,7 @@ import java.util.Map;
|
||||||
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
|
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8038500 8040059 8150366 8150496 8147539
|
* @bug 8038500 8040059 8150366 8150496 8147539 8290047
|
||||||
* @summary Basic test for zip provider
|
* @summary Basic test for zip provider
|
||||||
*
|
*
|
||||||
* @modules jdk.zipfs
|
* @modules jdk.zipfs
|
||||||
|
@ -89,7 +89,7 @@ public class Basic {
|
||||||
// Test: copy file from zip file to current (scratch) directory
|
// Test: copy file from zip file to current (scratch) directory
|
||||||
Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider");
|
Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider");
|
||||||
if (Files.exists(source)) {
|
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);
|
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
try {
|
try {
|
||||||
long s1 = Files.readAttributes(source, BasicFileAttributes.class).size();
|
long s1 = Files.readAttributes(source, BasicFileAttributes.class).size();
|
||||||
|
@ -113,6 +113,19 @@ public class Basic {
|
||||||
throw new RuntimeException("watch service is not supported");
|
throw new RuntimeException("watch service is not supported");
|
||||||
} catch (ProviderMismatchException x) { }
|
} 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
|
// Test: ClosedFileSystemException
|
||||||
fs.close();
|
fs.close();
|
||||||
if (fs.isOpen())
|
if (fs.isOpen())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue