Skip to content

Commit

Permalink
8289689: (fs) Re-examine the need for normalization to Unicode Normal…
Browse files Browse the repository at this point in the history
…ization Format D (macOS)

Reviewed-by: jpai, alanb
  • Loading branch information
Brian Burkhalter committed Nov 3, 2022
1 parent b7442d1 commit 25dfcbd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
35 changes: 26 additions & 9 deletions src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystem.java
@@ -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
Expand All @@ -26,6 +26,7 @@
package sun.nio.fs;

import java.util.regex.Pattern;
import sun.security.action.GetPropertyAction;

import static sun.nio.fs.MacOSXNativeDispatcher.*;

Expand All @@ -35,6 +36,18 @@

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) {
super(provider, dir);
}
Expand All @@ -46,21 +59,25 @@ Pattern compilePathMatchPattern(String expr) {

@Override
String normalizeNativePath(String path) {
for (int i = 0; i < path.length(); i++) {
char c = path.charAt(i);
if (c > 0x80)
return new String(normalizepath(path.toCharArray(),
if (NORMALIZE_FILE_PATHS) {
for (int i = 0; i < path.length(); i++) {
char c = path.charAt(i);
if (c > 0x80)
return new String(normalizepath(path.toCharArray(),
kCFStringNormalizationFormD));
}
}
return path;
}

@Override
String normalizeJavaPath(String path) {
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) > 0x80)
return new String(normalizepath(path.toCharArray(),
kCFStringNormalizationFormC));
if (NORMALIZE_FILE_PATHS) {
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) > 0x80)
return new String(normalizepath(path.toCharArray(),
kCFStringNormalizationFormC));
}
}
return path;
}
Expand Down
11 changes: 8 additions & 3 deletions test/jdk/java/nio/file/Path/MacPath.java
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,10 +27,13 @@
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.Set;
import java.util.regex.Pattern;

public class MacPath {
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
"jdk.nio.path.useNormalizationFormD";

public static void main(String args[]) throws Throwable {
System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n",
Expand Down Expand Up @@ -81,8 +84,10 @@ private static void test(String testdir, String dname, String fname_nfc)
throws Throwable
{
String fname = null;
String dname_nfd = Normalizer.normalize(dname, Normalizer.Form.NFD);
String fname_nfd = Normalizer.normalize(fname_nfc, Normalizer.Form.NFD);
Normalizer.Form form = Boolean.getBoolean(PROPERTY_NORMALIZE_FILE_PATHS)
? 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");
Path bpath = Paths.get(testdir);
Expand Down
17 changes: 14 additions & 3 deletions test/jdk/java/nio/file/Path/MacPathTest.java
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,7 +22,7 @@
*/

/* @test
* @bug 7130915
* @bug 7130915 8289689
* @summary Tests file path with nfc/nfd forms on MacOSX
* @requires (os.family == "mac")
* @library /test/lib ..
Expand All @@ -34,14 +34,25 @@
* jdk.test.lib.process.*
* TestUtil MacPath
* @run main MacPathTest
* @run main/othervm -Djdk.nio.path.useNormalizationFormD=true MacPathTest
*/

import jdk.test.lib.process.ProcessTools;

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 {
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");
ProcessTools.executeProcess(pb)
.outputTo(System.out)
Expand Down

1 comment on commit 25dfcbd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.