Przeglądaj źródła

Loaders, Editor: Improve handling of assets with unicode characters. (#33301)

Michael Herzog 3 miesięcy temu
rodzic
commit
3105f51c85
2 zmienionych plików z 26 dodań i 1 usunięć
  1. 21 1
      editor/js/Loader.js
  2. 5 0
      src/loaders/LoadingManager.js

+ 21 - 1
editor/js/Loader.js

@@ -45,6 +45,14 @@ function Loader( editor ) {
 				while ( normalized.startsWith( '../' ) ) normalized = normalized.slice( 3 );
 				while ( normalized.startsWith( '/' ) ) normalized = normalized.slice( 1 );
 
+				try {
+
+					normalized = decodeURIComponent( normalized );
+
+				} catch ( e ) { /* malformed URI — keep as-is */ }
+
+				normalized = normalized.normalize( 'NFC' );
+
 				return normalized;
 
 			};
@@ -956,10 +964,22 @@ function Loader( editor ) {
 
 		const zip = unzipSync( new Uint8Array( contents ) );
 
+		// Build a lookup map with NFC-normalized keys to handle
+		// unicode normalization differences (e.g. NFD vs NFC)
+
+		const zipLookup = {};
+
+		for ( const path in zip ) {
+
+			zipLookup[ path.normalize( 'NFC' ) ] = zip[ path ];
+
+		}
+
 		const manager = new THREE.LoadingManager();
 		manager.setURLModifier( function ( url ) {
 
-			const file = zip[ url ];
+			const normalized = decodeURIComponent( url ).normalize( 'NFC' );
+			const file = zipLookup[ normalized ];
 
 			if ( file ) {
 

+ 5 - 0
src/loaders/LoadingManager.js

@@ -156,6 +156,11 @@ class LoadingManager {
 		 */
 		this.resolveURL = function ( url ) {
 
+			// Normalize to NFC so that Unicode URIs (e.g. from glTF)
+			// are percent-encoded correctly per RFC 3987.
+
+			url = url.normalize( 'NFC' );
+
 			if ( urlModifier ) {
 
 				return urlModifier( url );

粤ICP备19079148号