@@ -241,3 +241,27 @@ func TestGetFileHistoryNotOnMaster(t *testing.T) {
241241
242242 assert .Equal (t , "1" , resp .Header ().Get ("X-Total" ))
243243}
244+
245+ func TestGetFileHistoryEmptyDateRange (t * testing.T ) {
246+ defer tests .PrepareTestEnv (t )()
247+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
248+ // Login as User2.
249+ session := loginUser (t , user .Name )
250+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeReadRepository )
251+
252+ // readme.md exists in repo16 but no commits fall before 1970, so the date
253+ // filter yields an empty range: this must return 200 with an empty list,
254+ // not 404 (regression: a valid path with an empty date range was a 404).
255+ req := NewRequestf (t , "GET" , "/api/v1/repos/%s/repo16/commits?path=readme.md&sha=good-sign&until=1970-01-01T00:00:00Z" , user .Name ).
256+ AddTokenAuth (token )
257+ resp := MakeRequest (t , req , http .StatusOK )
258+
259+ apiData := DecodeJSON (t , resp , []api.Commit {})
260+ assert .Empty (t , apiData )
261+ assert .Equal (t , "0" , resp .Header ().Get ("X-Total" ))
262+
263+ // a path that does not exist must still return 404 even with a date filter
264+ req = NewRequestf (t , "GET" , "/api/v1/repos/%s/repo16/commits?path=does-not-exist.md&sha=good-sign&until=1970-01-01T00:00:00Z" , user .Name ).
265+ AddTokenAuth (token )
266+ MakeRequest (t , req , http .StatusNotFound )
267+ }
0 commit comments