mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8289689: (fs) Re-examine the need for normalization to Unicode Normalization Format D (macOS)
Reviewed-by: jpai, alanb
This commit is contained in:
parent
b7442d12e2
commit
25dfcbdea5
3 changed files with 48 additions and 15 deletions
|
@ -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
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
package sun.nio.fs;
|
package sun.nio.fs;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import sun.security.action.GetPropertyAction;
|
||||||
|
|
||||||
import static sun.nio.fs.MacOSXNativeDispatcher.*;
|
import static sun.nio.fs.MacOSXNativeDispatcher.*;
|
||||||
|
|
||||||
|
@ -35,6 +36,18 @@ import static sun.nio.fs.MacOSXNativeDispatcher.*;
|
||||||
|
|
||||||
class MacOSXFileSystem extends BsdFileSystem {
|
class MacOSXFileSystem extends BsdFileSystem {
|
||||||
|
|
||||||
|
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||||
|
"jdk.nio.path.useNormalizationFormD";
|
||||||
|
|
||||||
|
private static final boolean NORMALIZE_FILE_PATHS;
|
||||||
|
|
||||||
|
static {
|
||||||
|
final String name = PROPERTY_NORMALIZE_FILE_PATHS;
|
||||||
|
String value = GetPropertyAction.privilegedGetProperty(name);
|
||||||
|
NORMALIZE_FILE_PATHS = (value != null)
|
||||||
|
&& ("".equals(value) || Boolean.parseBoolean(value));
|
||||||
|
}
|
||||||
|
|
||||||
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
|
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||||
super(provider, dir);
|
super(provider, dir);
|
||||||
}
|
}
|
||||||
|
@ -46,21 +59,25 @@ class MacOSXFileSystem extends BsdFileSystem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String normalizeNativePath(String path) {
|
String normalizeNativePath(String path) {
|
||||||
for (int i = 0; i < path.length(); i++) {
|
if (NORMALIZE_FILE_PATHS) {
|
||||||
char c = path.charAt(i);
|
for (int i = 0; i < path.length(); i++) {
|
||||||
if (c > 0x80)
|
char c = path.charAt(i);
|
||||||
return new String(normalizepath(path.toCharArray(),
|
if (c > 0x80)
|
||||||
|
return new String(normalizepath(path.toCharArray(),
|
||||||
kCFStringNormalizationFormD));
|
kCFStringNormalizationFormD));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String normalizeJavaPath(String path) {
|
String normalizeJavaPath(String path) {
|
||||||
for (int i = 0; i < path.length(); i++) {
|
if (NORMALIZE_FILE_PATHS) {
|
||||||
if (path.charAt(i) > 0x80)
|
for (int i = 0; i < path.length(); i++) {
|
||||||
return new String(normalizepath(path.toCharArray(),
|
if (path.charAt(i) > 0x80)
|
||||||
kCFStringNormalizationFormC));
|
return new String(normalizepath(path.toCharArray(),
|
||||||
|
kCFStringNormalizationFormC));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2017, 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
|
||||||
|
@ -27,10 +27,13 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
import java.text.Normalizer;
|
import java.text.Normalizer;
|
||||||
|
import java.text.Normalizer.Form;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MacPath {
|
public class MacPath {
|
||||||
|
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||||
|
"jdk.nio.path.useNormalizationFormD";
|
||||||
|
|
||||||
public static void main(String args[]) throws Throwable {
|
public static void main(String args[]) throws Throwable {
|
||||||
System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n",
|
System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n",
|
||||||
|
@ -81,8 +84,10 @@ public class MacPath {
|
||||||
throws Throwable
|
throws Throwable
|
||||||
{
|
{
|
||||||
String fname = null;
|
String fname = null;
|
||||||
String dname_nfd = Normalizer.normalize(dname, Normalizer.Form.NFD);
|
Normalizer.Form form = Boolean.getBoolean(PROPERTY_NORMALIZE_FILE_PATHS)
|
||||||
String fname_nfd = Normalizer.normalize(fname_nfc, Normalizer.Form.NFD);
|
? Normalizer.Form.NFD : Normalizer.Form.NFC;
|
||||||
|
String dname_nfd = Normalizer.normalize(dname, form);
|
||||||
|
String fname_nfd = Normalizer.normalize(fname_nfc, form);
|
||||||
|
|
||||||
System.out.printf("%n%n--------Testing...----------%n");
|
System.out.printf("%n%n--------Testing...----------%n");
|
||||||
Path bpath = Paths.get(testdir);
|
Path bpath = Paths.get(testdir);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 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 7130915
|
* @bug 7130915 8289689
|
||||||
* @summary Tests file path with nfc/nfd forms on MacOSX
|
* @summary Tests file path with nfc/nfd forms on MacOSX
|
||||||
* @requires (os.family == "mac")
|
* @requires (os.family == "mac")
|
||||||
* @library /test/lib ..
|
* @library /test/lib ..
|
||||||
|
@ -34,14 +34,25 @@
|
||||||
* jdk.test.lib.process.*
|
* jdk.test.lib.process.*
|
||||||
* TestUtil MacPath
|
* TestUtil MacPath
|
||||||
* @run main MacPathTest
|
* @run main MacPathTest
|
||||||
|
* @run main/othervm -Djdk.nio.path.useNormalizationFormD=true MacPathTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jdk.test.lib.process.ProcessTools;
|
import jdk.test.lib.process.ProcessTools;
|
||||||
|
|
||||||
public class MacPathTest {
|
public class MacPathTest {
|
||||||
|
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||||
|
"jdk.nio.path.useNormalizationFormD";
|
||||||
|
private static final boolean NORMALIZE_FILE_PATHS =
|
||||||
|
Boolean.getBoolean(PROPERTY_NORMALIZE_FILE_PATHS);
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
ProcessBuilder pb = ProcessTools.createTestJvm(MacPath.class.getName());
|
ProcessBuilder pb;
|
||||||
|
if (NORMALIZE_FILE_PATHS) {
|
||||||
|
String option = "-D" + PROPERTY_NORMALIZE_FILE_PATHS + "=true";
|
||||||
|
pb = ProcessTools.createTestJvm(option, MacPath.class.getName());
|
||||||
|
} else {
|
||||||
|
pb = ProcessTools.createTestJvm(MacPath.class.getName());
|
||||||
|
}
|
||||||
pb.environment().put("LC_ALL", "en_US.UTF-8");
|
pb.environment().put("LC_ALL", "en_US.UTF-8");
|
||||||
ProcessTools.executeProcess(pb)
|
ProcessTools.executeProcess(pb)
|
||||||
.outputTo(System.out)
|
.outputTo(System.out)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue