8181#include " utilities/ostream.hpp"
8282#include " utilities/utf8.hpp"
8383
84+ #include < stdlib.h>
85+ #include < ctype.h>
86+
8487// Entry point in java.dll for path canonicalization
8588
8689typedef int (*canonicalize_fn_t )(const char *orig, char *out, int len);
@@ -1209,7 +1212,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo
12091212}
12101213
12111214#if INCLUDE_CDS
1212- char * ClassLoader:: skip_uri_protocol (char * source) {
1215+ static const char * skip_uri_protocol (const char * source) {
12131216 if (strncmp (source, " file:" , 5 ) == 0 ) {
12141217 // file: protocol path could start with file:/ or file:///
12151218 // locate the char after all the forward slashes
@@ -1228,6 +1231,47 @@ char* ClassLoader::skip_uri_protocol(char* source) {
12281231 return source;
12291232}
12301233
1234+ static char decode_percent_encoded (const char *str, size_t & index) {
1235+ if (str[index] == ' %'
1236+ && isxdigit (str[index + 1 ])
1237+ && isxdigit (str[index + 2 ])) {
1238+ char hex[3 ];
1239+ hex[0 ] = str[index + 1 ];
1240+ hex[1 ] = str[index + 2 ];
1241+ hex[2 ] = ' \0 ' ;
1242+ index += 2 ;
1243+ return (char ) strtol (hex, NULL , 16 );
1244+ }
1245+ return str[index];
1246+ }
1247+
1248+ char * ClassLoader::uri_to_path (const char * uri) {
1249+ const size_t len = strlen (uri) + 1 ;
1250+ char * path = NEW_RESOURCE_ARRAY (char , len);
1251+
1252+ uri = skip_uri_protocol (uri);
1253+
1254+ if (strncmp (uri, " //" , 2 ) == 0 ) {
1255+ // Skip the empty "authority" part
1256+ uri += 2 ;
1257+ }
1258+
1259+ #ifdef _WINDOWS
1260+ if (uri[0 ] == ' /' ) {
1261+ // Absolute path name on Windows does not begin with a slash
1262+ uri += 1 ;
1263+ }
1264+ #endif
1265+
1266+ size_t path_index = 0 ;
1267+ for (size_t i = 0 ; i < strlen (uri); ++i) {
1268+ char decoded = decode_percent_encoded (uri, i);
1269+ path[path_index++] = decoded;
1270+ }
1271+ path[path_index] = ' \0 ' ;
1272+ return path;
1273+ }
1274+
12311275// Record the shared classpath index and loader type for classes loaded
12321276// by the builtin loaders at dump time.
12331277void ClassLoader::record_result (JavaThread* current, InstanceKlass* ik,
@@ -1261,7 +1305,7 @@ void ClassLoader::record_result(JavaThread* current, InstanceKlass* ik,
12611305 // Save the path from the file: protocol or the module name from the jrt: protocol
12621306 // if no protocol prefix is found, path is the same as stream->source(). This path
12631307 // must be valid since the class has been successfully parsed.
1264- char * path = skip_uri_protocol (src);
1308+ const char * path = ClassLoader::uri_to_path (src);
12651309 assert (path != nullptr , " sanity" );
12661310 for (int i = 0 ; i < FileMapInfo::get_number_of_shared_paths (); i++) {
12671311 SharedClassPathEntry* ent = FileMapInfo::shared_path (i);
0 commit comments