Fix stripping of slashes from paths #486
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Our team ran into issues where slashes were being stripped when a filepath with a protocol was supplied. For example, say
duck.gltf
referencesducktex.png
. If we supplied a URI likefile://duck.gltf
into tinygltf it would search forfile:/ducktex.png
(note the single slash).This is because
GetBaseDir()
strips out the final slash. In most cases this is fine becauseJoinPath()
adds the "/" back in. However,JoinPath()
has the following check:This means that for the "file://duck.gltf" case,
GetBaseDir("file://duck.gltf") = "file:/"
. And thenJoinPath("file:/", "ducktext.png") = "file:/ducktext.png"
.The simple solution in this PR is to just leave the slash in when getting the base directory. I'm happy to modify
JoinPath
as well if you would like (I think we can remove the special if logic but wanted to keep this diff as simple as possible).Testing
Ran tests using the test_runner: