8289689: (fs) Re-examine the need for normalization to Unicode Normalization Format D (macOS)

Reviewed-by: jpai, alanb
This commit is contained in:
Brian Burkhalter 2022-11-03 15:47:51 +00:00
parent b7442d12e2
commit 25dfcbdea5
3 changed files with 48 additions and 15 deletions

View file

@ -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
@ -26,6 +26,7 @@
package sun.nio.fs;
import java.util.regex.Pattern;
import sun.security.action.GetPropertyAction;
import static sun.nio.fs.MacOSXNativeDispatcher.*;
@ -35,6 +36,18 @@ import static sun.nio.fs.MacOSXNativeDispatcher.*;
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);
}
@ -46,21 +59,25 @@ class MacOSXFileSystem extends BsdFileSystem {
@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;
}