diff --git a/src/Microsoft.AspNetCore.OData/Batch/ODataBatchReaderExtensions.cs b/src/Microsoft.AspNetCore.OData/Batch/ODataBatchReaderExtensions.cs index 638eb6af6e..e054e0fa57 100644 --- a/src/Microsoft.AspNetCore.OData/Batch/ODataBatchReaderExtensions.cs +++ b/src/Microsoft.AspNetCore.OData/Batch/ODataBatchReaderExtensions.cs @@ -332,6 +332,11 @@ private static string MergeIndividualAndBatchPreferences(string individualPrefer .Where(pref => !individualPreferenceNames.Contains(pref.Split('=').FirstOrDefault())); string filteredBatchPreferences = string.Join(",", filteredBatchList); + if (string.IsNullOrEmpty(filteredBatchPreferences)) + { + return individualPreferences; + } + return string.Join(",", individualPreferences, filteredBatchPreferences); } diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Batch/DefaultODataBatchHandlerTest.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Batch/DefaultODataBatchHandlerTest.cs index 0ed98616be..4b7a6fcf0b 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Batch/DefaultODataBatchHandlerTest.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Batch/DefaultODataBatchHandlerTest.cs @@ -561,6 +561,16 @@ public async Task SendAsync_Works_ForBatchRequestWithInsertedEntityReferencedInA "DELETE,ContentType=,ContentLength=,Prefer=wait=100,handling=lenient", "POST,ContentType=text/plain; charset=utf-8,ContentLength=3,Prefer=" }, + { + // should not concatenate preferences that should not be inherited + new [] + { + "wait=100,handling=lenient" + }, + "GET,ContentType=,ContentLength=,Prefer=", + "DELETE,ContentType=,ContentLength=,Prefer=wait=100,handling=lenient", + "POST,ContentType=text/plain; charset=utf-8,ContentLength=3,Prefer=" + }, { // inheritable preferences should be copied over // and combined with the individual request's own preferences if any