diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55f003b056..a7056afed3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,7 @@ release.
- Fixed a bug in which 'version' file was compiled as source and prevented subsequent ISIS recompilation [#5374](https://github.com/DOI-USGS/ISIS3/issues/5374)
- Fixed noproj bug where some temporary files were not deleted after call to cam2cam. Issue: [#4813](https://github.com/USGS-Astrogeology/ISIS3/issues/4813)
- Fixed noproj bug where missing shapemodel-related keywords (RayTraceEngine, BulletParts, Tolerance) are dropped when the output label is created. This resulted in the Bullet collision detection engine not being used. Issue: [#5377](https://github.com/USGS-Astrogeology/ISIS3/issues/5377)
+- Fixed ISIS failing to expand env variables with an "_" in them. [#5402](https://github.com/DOI-USGS/ISIS3/pull/5402)
## [8.0.2] - 2023-12-05
### Changed
diff --git a/isis/src/base/objs/FileName/FileName.cpp b/isis/src/base/objs/FileName/FileName.cpp
index 8927da9636..425e0801a5 100644
--- a/isis/src/base/objs/FileName/FileName.cpp
+++ b/isis/src/base/objs/FileName/FileName.cpp
@@ -846,7 +846,7 @@ namespace Isis {
// Loop while there are any "$" at the current position or after
// Some "$" might be skipped if no translation can be found
while((varStartPos = expandedStr.indexOf("$", varSearchStartPos)) != -1) {
- int varEndPos = expandedStr.indexOf(QRegExp("[^a-zA-Z{}0-9]"), varStartPos + 1);
+ int varEndPos = expandedStr.indexOf(QRegExp("[^a-zA-Z{}0-9_]"), varStartPos + 1);
if (varEndPos == -1)
varEndPos = expandedStr.length();
diff --git a/isis/tests/FileNameTests.cpp b/isis/tests/FileNameTests.cpp
index fc8aa4b345..ce19019a71 100644
--- a/isis/tests/FileNameTests.cpp
+++ b/isis/tests/FileNameTests.cpp
@@ -84,13 +84,21 @@ TEST(FileName, Extension) {
EXPECT_EQ("cub", file.extension());
}
-TEST(FileName, Expanded) {
+TEST(FileName, ExpandedDefault) {
QString relativeFileName("test.cub");
FileName file("$ISISROOT/" + relativeFileName);
QString isisRoot(getenv("ISISROOT"));
EXPECT_EQ(isisRoot + "/" + relativeFileName, file.expanded());
}
+TEST(FileName, ExpandedUnderscore) {
+ QString relativeFileName("test.cub");
+ setenv("SOME_FILE_PATH", getenv("ISISROOT"), 1);
+ FileName file("$SOME_FILE_PATH/" + relativeFileName);
+ QString someFilePath(getenv("ISISROOT"));
+ EXPECT_EQ(someFilePath + "/" + relativeFileName, file.expanded());
+}
+
TEST(FileName, Original) {
QString test = "$ISISROOT/testy/mc/test/face/test.cub";
FileName file(test);