Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODataPathSegmentHandler encoding of string values does not allign with ODataUriParser #1390

Open
uffelauesen opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@uffelauesen
Copy link
Contributor

uffelauesen commented Jan 13, 2025

Assemblies affected
ASP.NET Core OData 8.x++

Describe the bug
String key values end up unencoded encoded in odata.id, odata.readLink, odata.editLink as well as Location header. Client side on OData Client library you can end up with two representations of the same oblect in DataServiceContext's Entities tracked collection as the OData ID get constructed differently.

Reproduce steps
Given an entity type with a string key property ID. Create an object of that type with ID = "'24 25/&Foo,?"".
Then do a GET request with OData Client for that object with and without selecting the ID, like...

var result1 = new DataServiceCollection<MyEntity>(
    from e in ctx.MyEntities 
    where e.ID == "'24 25/&Foo,?\"" 
    select new MyEntity { Title = e.Title } // AspNetCoreOData will generate and send the odata.id
);
var result2 = new DataServiceCollection<MyEntity>(
    from e in ctx.MyEntities 
    where e.ID == "'24 25/&Foo,?\"" 
    select new MyEntity { ID = e.ID } // OData Lib will generate the odata.id from the returned ID attribute
);

Assert.AreEqual(1, result1.Count);
Assert.AreEqual(1, result2.Count);
Assert.AreEqual(1, ctx.Entities.Count); // <- Exception here!!! ctx.Entities.Count is 2
Assert.AreEqual(result1.First(), result2.First());

Data Model
Given an entity type with a string key property ID. Create an object of that type with ID = "'24 25/&Foo,?"".

Expected behavior
OData Clinet and AspNetCoreOData will generate the same Uri's.

Additional context
I originally reported this bug under OData Lib, but it is actually a bug in AspNetODataCore. You can find the original report as #2857 OData/odata.net#2857

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant