Skip to content

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

@uffelauesen

Description

@uffelauesen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions