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

Text "Date" will be parsed as "EDM.Date" type segment in URL parser #680

LianwMS opened this Issue Aug 12, 2016 · 2 comments


None yet
3 participants

LianwMS commented Aug 12, 2016

Short summary (3-5 sentences) describing the issue.
During the parsing of the following URL (KeyAsSegment): "https://localhost/beta/me/EntityA/Date", "Data" will be parsed as type segment, which does not follow the protocol.

Assemblies affected

ODL 6.x and 7.x

Reproduce steps

Parse "https://localhost/beta/me/EntityA/Date" with KeyAsSegment settings.
The type of key in EntityA is string.

Expected result

Date should be a KeySegment.

Actual result

Date is a typesegment.

Additional details

FindDeclaredType in Edm lib will find type "Edm.Data" given "Date"

@Lingxi-Li Lingxi-Li added the bug label Aug 24, 2016

@Lingxi-Li Lingxi-Li self-assigned this Aug 24, 2016

@Lingxi-Li Lingxi-Li removed the bug label Aug 24, 2016


This comment has been minimized.


Lingxi-Li commented Aug 24, 2016

A simple test case that reproduces the issue:

var model = new EdmModel();
var entityType = new EdmEntityType("NS", "Entity");
entityType.AddKeys(entityType.AddStructuralProperty("IdStr", EdmPrimitiveTypeKind.String, false));
var container = new EdmEntityContainer("NS", "Container");
var set = container.AddEntitySet("Set", entityType);
model.AddElements(new IEdmSchemaElement[] { entityType, container });

var svcRoot = new Uri("http://host", UriKind.Absolute);
var parseResult = new ODataUriParser(model, svcRoot, new Uri("http://host/Set/Date", UriKind.Absolute)).ParseUri();

It actually results in an exception

Microsoft.OData.ODataException : The type 'Edm.Date' specified in the URI is neither a base type nor a sub-type of the previously-specified type 'NS.Entity'.

This is exactly because Date is interpreted as a type-cast segment.

But the real question here is whether this is a bug or expected behavior. According to the spec, string literals are those enclosed within single-quotes. Since you are giving in the key segment the literal value for a string-typed key, It should, in theory, follow the string-literal syntax. Therefore, a correct key-as-segment request URL should be http://host/Set/'Date' instead of http://host/Set/Date. The library works out just fine on the former.


This comment has been minimized.


Lingxi-Li commented Aug 24, 2016

This looks like an issue anyway. In the spec, type-cast is associated with qualified type name. A qualified name should contain a namespace part. In other words, Date should not be interpreted as a type-cast segment anyway; only Edm.Date should. I'm going to fix this. After that, Date in this case should be interpreted as a key segment even though it's not enclosed within single-quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment