Skip to content

Commit

Permalink
TC 2024-06-26: No implicit cast, static rejection recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Jun 27, 2024
1 parent f072d24 commit 1291683
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
7 changes: 4 additions & 3 deletions docs/odata-url-conventions/odata-url-conventions.html
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ <h3 id="511-common-expression-syntax"><a name="CommonExpressionSyntax" href="#Co
</summary>
<p>The following operators, functions, and literals can be used in <code>$filter</code>, <code>$orderby</code>, and <code>$compute</code> expressions.</p>
<p>The <a href="#ODataABNF">OData-ABNF</a> <code>commonExpr</code> syntax rule defines the formal grammar of common expressions.</p>
<p>The following subsections specify situations in which expressions evaluate to <code>null</code> if operands or parameters do not have the types expected by an operator or function. Notwithstanding these rules, if such a type discrepancy can be inferred for an expression that appears in a request, services SHOULD reject the request with an error message explaining the discrepancy. The inferral could be based on, for example, the declared type of a property or the type of a literal value that occurs in the expression.</p>
<details open><summary>
<h4 id="5111-logical-operators"><a name="LogicalOperators" href="#LogicalOperators">5.1.1.1 Logical Operators</a></h4>
</summary>
Expand Down Expand Up @@ -1115,7 +1116,7 @@ <h5 id="511110-has"><a name="Has" href="#Has">5.1.1.1.10 Has</a></h5>
<details open><summary>
<h5 id="511111-in"><a name="In" href="#In">5.1.1.1.11 In</a></h5>
</summary>
<p>The <code>in</code> operator returns <code>true</code> if the left operand <a href="#Equals">equals</a> a member of the right operand. The right operand MUST be either a comma-separated list of zero or more primitive values, enclosed in parentheses, or a single expression that resolves to a collection. If the right operand is an empty collection or list of values, the <code>in</code> operator returns <code>false</code>.</p>
<p>The <code>in</code> operator returns <code>true</code> if the <a href="#Equals">equality</a> comparison of the left operand with at least one member of the right operand returns <code>true</code>. The right operand MUST be either a comma-separated list of zero or more primitive values, enclosed in parentheses, or a single expression that resolves to a collection. If the right operand is an empty collection or list of values, the <code>in</code> operator returns <code>false</code>.</p>
</details>
<details open><summary>
<h5 id="511112-logical-operator-examples"><a name="LogicalOperatorExamples" href="#LogicalOperatorExamples">5.1.1.1.12 Logical Operator Examples</a></h5>
Expand Down Expand Up @@ -1280,7 +1281,7 @@ <h4 id="5114-canonical-functions"><a name="CanonicalFunctions" href="#CanonicalF
</summary>
<p>In addition to operators, a set of functions is also defined for use with the <a href="#SystemQueryOptioncompute"><code>$compute</code></a>, <code>$filter</code> or <a href="#SystemQueryOptionorderby"><code>$orderby</code></a> system query options, or in <a href="#ParameterAliases">parameter alias</a> values. The following sections describe the available functions.</p>
<p>Note: ISNULL or COALESCE operators are not defined. Instead, OData defines a <a href="#null"><code>null</code></a> literal that can be used in comparisons.</p>
<p>If a parameter of a canonical function is <code>null</code>, the function returns <code>null</code>. If the parameters cannot be <a href="#cast">cast</a> to match the function signature, the function also returns <code>null</code>.</p>
<p>If a parameter of a canonical function is <code>null</code>, the function returns <code>null</code>. If the types of parameters do not match the function signature, the function also returns <code>null</code>.</p>
<p>The syntax rules for all functions are defined in <a href="#ODataABNF">OData-ABNF</a>. 4.01 Services MUST support case-insensitive canonical function names. Clients that want to work with 4.0 services MUST use lower case canonical function names.</p>
</details>
<details open><summary>
Expand Down Expand Up @@ -1701,7 +1702,6 @@ <h5 id="511101-cast"><a name="cast" href="#cast">5.1.1.10.1 <code>cast</code></a
<li>String values containing a representation of a date-time value according to <a href="#XML-Schema2">XML-Schema-2</a>, <a href="https://www.w3.org/TR/xmlschema11-2/#dateTime">section 3.3.7 dateTime</a>, can be cast to <code>Edm.DateTimeOffset</code>. If the string value does not contain a time-zone offset, it is treated as UTC.</li>
</ol>
<p>If the cast fails, the <code>cast</code> function returns <code>null</code>.</p>
<p>When a parameter of a canonical function or a service-defined action or function <a href="#ODataCSDL">OData-CSDL, section 12.9</a> is given a value that can be cast to the parameter type with one of the first five rules (for primitive values) or the seventh rule (for structured values), this cast is silently carried out.</p>
</details>
<details open><summary>
<h5 id="511102-isof"><a name="isof" href="#isof">5.1.1.10.2 <code>isof</code></a></h5>
Expand Down Expand Up @@ -2110,6 +2110,7 @@ <h4 id="51118-numeric-promotion"><a name="NumericPromotion" href="#NumericPromot
<li>Otherwise, if either operand is <code>Edm.Int16</code>, the other operand is converted to type <code>Edm.Int16</code>.</li>
</ul>
<p>Each of these promotions uses the same semantics as a <code>castExpression</code> to promote an operand to the target type.</p>
<p>OData does not define an implicit conversion between string and numeric types.</p>
</details>
</details>
<details open><summary>
Expand Down
24 changes: 15 additions & 9 deletions docs/odata-url-conventions/odata-url-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,14 @@ The following operators, functions, and literals can be used in
The [OData-ABNF](#ODataABNF) `commonExpr` syntax rule defines the formal
grammar of common expressions.

The following subsections specify situations in which expressions evaluate to `null`
if operands or parameters do not have the types expected by an operator or function.
Notwithstanding these rules, if such a type discrepancy can be inferred for an expression
that appears in a request, services SHOULD reject the request with an error message
explaining the discrepancy. The inferral could be based on, for example, the
declared type of a property or the type of a literal value that occurs in the
expression.

#### <a name="LogicalOperators" href="#LogicalOperators">5.1.1.1 Logical Operators</a>

OData defines a set of logical operators that evaluate to `true` or `false`
Expand Down Expand Up @@ -1726,8 +1734,9 @@ The `null` value is treated as unknown, so if one operand evaluates to

##### <a name="In" href="#In">5.1.1.1.11 In</a>

The `in` operator returns `true` if the left operand [equals](#Equals) a member of
the right operand. The right operand MUST be either a comma-separated list
The `in` operator returns `true` if the [equality](#Equals) comparison of the left
operand with at least one member of the right operand returns `true`.
The right operand MUST be either a comma-separated list
of zero or more primitive values, enclosed in parentheses, or a single expression
that resolves to a collection. If the right operand is an empty collection
or list of values, the `in` operator returns `false`.
Expand Down Expand Up @@ -2016,7 +2025,7 @@ not defined. Instead, OData defines a [`null`](#null) literal that can
be used in comparisons.

If a parameter of a canonical function is `null`, the function returns
`null`. If the parameters cannot be [cast](#cast) to match the function signature,
`null`. If the types of parameters do not match the function signature,
the function also returns `null`.

The syntax rules for all functions are defined in
Expand Down Expand Up @@ -2838,12 +2847,6 @@ The `cast` function follows these assignment rules:

If the cast fails, the `cast` function returns `null`.

When a parameter of a canonical function or a service-defined action or function
[OData-CSDL, section 12.9](#ODataCSDL)
is given a value that can be cast to the parameter type with one of the first five rules
(for primitive values) or the seventh rule (for structured values), this cast
is silently carried out.

##### <a name="isof" href="#isof">5.1.1.10.2 `isof`</a>

The `isof` function has the following signatures
Expand Down Expand Up @@ -3429,6 +3432,9 @@ rules, in order:
Each of these promotions uses the same semantics as a `castExpression`
to promote an operand to the target type.

OData does not define an implicit conversion between string and numeric
types.

### <a name="SystemQueryOptionfilter" href="#SystemQueryOptionfilter">5.1.2 System Query Option `$filter`</a>

The `$filter` system query option allows clients to filter a collection
Expand Down
24 changes: 15 additions & 9 deletions odata-url-conventions/5 Query Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ The following operators, functions, and literals can be used in
The [OData-ABNF](#ODataABNF) `commonExpr` syntax rule defines the formal
grammar of common expressions.

The following subsections specify situations in which expressions evaluate to `null`
if operands or parameters do not have the types expected by an operator or function.
Notwithstanding these rules, if such a type discrepancy can be inferred for an expression
that appears in a request, services SHOULD reject the request with an error message
explaining the discrepancy. The inferral could be based on, for example, the
declared type of a property or the type of a literal value that occurs in the
expression.

#### ##subsubsubsec Logical Operators

OData defines a set of logical operators that evaluate to `true` or `false`
Expand Down Expand Up @@ -242,8 +250,9 @@ The `null` value is treated as unknown, so if one operand evaluates to

##### ##subsubsubsubsec In

The `in` operator returns `true` if the left operand [equals](#Equals) a member of
the right operand. The right operand MUST be either a comma-separated list
The `in` operator returns `true` if the [equality](#Equals) comparison of the left
operand with at least one member of the right operand returns `true`.
The right operand MUST be either a comma-separated list
of zero or more primitive values, enclosed in parentheses, or a single expression
that resolves to a collection. If the right operand is an empty collection
or list of values, the `in` operator returns `false`.
Expand Down Expand Up @@ -532,7 +541,7 @@ not defined. Instead, OData defines a [`null`](#null) literal that can
be used in comparisons.

If a parameter of a canonical function is `null`, the function returns
`null`. If the parameters cannot be [cast](#cast) to match the function signature,
`null`. If the types of parameters do not match the function signature,
the function also returns `null`.

The syntax rules for all functions are defined in
Expand Down Expand Up @@ -1355,12 +1364,6 @@ The `cast` function follows these assignment rules:

If the cast fails, the `cast` function returns `null`.

When a parameter of a canonical function or a service-defined action or function
[OData-CSDL, section 12.9](#ODataCSDL)
is given a value that can be cast to the parameter type with one of the first five rules
(for primitive values) or the seventh rule (for structured values), this cast
is silently carried out.

##### ##subsubsubsubsec `isof`

The `isof` function has the following signatures
Expand Down Expand Up @@ -1946,6 +1949,9 @@ rules, in order:
Each of these promotions uses the same semantics as a `castExpression`
to promote an operand to the target type.

OData does not define an implicit conversion between string and numeric
types.

### ##subsubsec System Query Option `$filter`

The `$filter` system query option allows clients to filter a collection
Expand Down

0 comments on commit 1291683

Please sign in to comment.