Legal characters for properties on an open-type entity

限于喜欢 提交于 2021-02-08 08:56:19

问题


I have implemented a WCD Data Services / OData server, with an entity set as an open type. I am using custom IMetadataProvider, IQueryProvider, etc. I can create my entity, set open properties, retrieve them, update, and search -- mostly. The problem comes when I attempt to search for a property with something like a "dash" in the name

This works:

GET /Service/Cases?$filter=ABC eq 'ABC'

This doesn't work:

GET /Service/Cases?$filter=A-BC eq 'ABC'

This also doesn't work:

GET /Service/Cases?$filter=A%2DBC eq 'ABC'

I get the following error:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code />
  <message xml:lang="en-US">Syntax error at position 7.</message>
</error>

(And as I said, I am able to get an entity with an open property with a dash in the name. And update it, etc.)

I would guess that whatever is parsing the URL is interpreting the dash as a subtraction expression, which makes sense. Except that if I read the OData spec correctly, an entity's property name is defined by entitySimpleProperty (which isn't defined in the spec, but I presume is a typo for entityProperty)... which is defined as *pchar, as defined in RFC 3986 section 3.3. That, in turn, evaluates to...

pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

Where ALPHA is %41-%5A and %61-%7A, DIGIT is %30-%39, hyphen is %2D, period is %2E, underscore is %5F, and tilde is %7E.

And that shows that a dash is a legal character, coming full circle. Not that I need it to be. So, what part of the spec dictates what the allowable characters are?

Thanks for any help!


回答1:


A property must be valid as per CSDL (EDM) rules. That allows any valid identifier as defined for example by this piece of XSD:

  <xs:simpleType name="TSimpleIdentifier">
    <xs:restriction base="xs:string">
      <xs:maxLength value="480" />
      <!-- The below pattern represents the allowed identifiers in ECMA specification -->
      <xs:pattern value="[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}" />
    </xs:restriction>
  </xs:simpleType>

It's basically any valid programming language identifier. The OData spec might be a bit confusing (or maybe even wrong) on this unfortunately.

Note that WCF DS doesn't validate this in most cases since the validation check would be way too expensive. It relies on the IDataServiceMetadataProvider implementation to do the right thing. That's why you see it working in some cases and in some it doesn't.



来源:https://stackoverflow.com/questions/10923789/legal-characters-for-properties-on-an-open-type-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!