convert file ext to lowercase for format detection (#2121)

* convert file ext to lowercase for format detection

To ensure proper file format detection with case-insensitive file
systems.

* use filepath.Ext for more reliable file ext detection

especially for paths like index.js/foo

* add a test for file ext based format detection
This commit is contained in:
ryenus
2024-08-05 15:14:43 +10:00
committed by GitHub
parent b80e1cb35e
commit b9c3ff6f0a
2 changed files with 15 additions and 5 deletions
+10
View File
@@ -50,3 +50,13 @@ func TestFormatFromString(t *testing.T) {
}
}
}
func TestFormatStringFromFilename(t *testing.T) {
test.AssertResult(t, "yaml", FormatStringFromFilename("test.Yaml"))
test.AssertResult(t, "yaml", FormatStringFromFilename("test.index.Yaml"))
test.AssertResult(t, "yaml", FormatStringFromFilename("test"))
test.AssertResult(t, "json", FormatStringFromFilename("test.json"))
test.AssertResult(t, "json", FormatStringFromFilename("TEST.JSON"))
test.AssertResult(t, "yaml", FormatStringFromFilename("test.json/foo"))
test.AssertResult(t, "yaml", FormatStringFromFilename(""))
}