fix: only replace path with env var if value defined
fixes https://github.com/sindrets/diffview.nvim/issues/556
The code in question is trying to replace an environment variable name in a file path with it's value. It is assuming that if a segment starts with $ then it is an environment variable name. There are frontend frameworks with file-based routing that use $ to indicate a value in a path (ie https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing). We need to strip the $ off of the name to pass to os_getenv but If there isn't a value for the environment variable, we shouldn't remove the $ from the path since this is a valid file and directory name.
If we don't want to modify the existing method this way, we could also either
- pass a parameter to disable replacing segments with environment vars or
- make a separate method and only call the environment var version in a context where you would expect this behavior.
I don't have any strong opinions on this. Just would like to fix this bug. Please let me know if you would like any changes or additional test cases.
The fix works for me. Thanks @bryankenote
Hopefully this could be merged.
Bumping this as well. Hopefully this PR will be merged.