Three.js: ImageLoader does not URL-escape "+"

Created on 28 Dec 2017  路  4Comments  路  Source: mrdoob/three.js

Description of the problem

AWS S3 rejects + in URLs (on GETs), nonconformant to spec. See https://forums.aws.amazon.com/thread.jspa?messageID=722673

It would be nice if there was maybe a way to configure ImageLoader to escape its url's. It's unclear if it would be safe to just change ImageLoader to escape its url's. It would probably break people's stuff.

Since my app directly loads from S3 for the time being, I see no quick way to fix this without continually patching my three.js from now on. Kind of lame, so I'm sort of just asking folks for how they would address this type of issue. Thanks.

I'm even considering hacking my MTL file data (which contain the relative paths to the particular jpgs in question here) to escape those pluses, just so I can avoid maintaining an additional patch on a core dependency. Only because it turns out that this is still practical for me to do at this time.

Three.js version
  • [x] Dev
  • [x] r89
  • [x] r88

Most helpful comment

You can override request URLs for any of the loaders using a LoadingManager, as long as the loader uses its manager correctly;

var manager = new THREE.LoadingManager();
manager.setURLModifier( ( url ) => url.replace( /\+/g, '%2B' ) );

var mtlLoader = new THREE.MTLLoader( manager );
mtlLoader.load( 'my+materials.mtl', function () { ... } );  // '+' in URL will be escaped.

All 4 comments

You can override request URLs for any of the loaders using a LoadingManager, as long as the loader uses its manager correctly;

var manager = new THREE.LoadingManager();
manager.setURLModifier( ( url ) => url.replace( /\+/g, '%2B' ) );

var mtlLoader = new THREE.MTLLoader( manager );
mtlLoader.load( 'my+materials.mtl', function () { ... } );  // '+' in URL will be escaped.

Thank you so much

This may not be properly wired through with OBJLoader2 yet, but I should have enough information to get somewhere useful with it at least.

I will have a PR for OBJLoader2 shortly. It's just not passing the LoadingManager through.

edit here it is #12989

I do have a question though. It's clear to see that there exists a difference in behavior with e.g. the + URL-escapement between ImgLoader and FileLoader... how much of that matters since loading an MTL causes it to load both types of resources under the hood? I'm anticipating a problem as follows: I use a LoadingManager that turns + into %2B, and then for the FileLoaders that OBJLoader ends up using it will apply the regular escaping which it already does to turn %2B into %%2B which will then break the loading of non-images.

edit multiple url munging not happening, and adding the manager that @donmccurdy suggested fixes the issue for me once I updated OBJLoader2 to pass the loader into its MTLLoader.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filharvey picture filharvey  路  3Comments

jlaquinte picture jlaquinte  路  3Comments

scrubs picture scrubs  路  3Comments

makc picture makc  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments