Skip to content

validate: php refuses a null under a default, csharp differs from ts on three null cases, and the corpus cannot see either #170

Closed

Description

@rjrodger

Found while reviewing #169, which makes csharp keep a spec default for a null or absent value as typescript does. Each row below was run against typescript/dist on main.

php refuses a null under a default

typescript keeps the spec default for a null value exactly as for an absent key, since getprop answers NONE for a null. php refuses instead, for stdClass and assoc-array input alike:

call typescript php
validate({retries: null}, {retries: 3}) {retries: 3} Invalid data: Expected field retries to be integer, but found no value.
validate({auth: null}, {auth: {prefix: ''}}) {auth: {prefix: ''}} the map equivalent
validate({tags: null}, {tags: ['a', 'b']}) {tags: ['a', 'b']} the list equivalent

js, python, ruby, perl and go give typescript's answers. csharp did not either, and #169 fixes it. lua was not probed, since a Lua table cannot store a nil.

csharp differs from typescript on three more null cases

These predate #169, which leaves them as they were:

call typescript csharp
validate({a: 1}, {a: null}) (a null spec value) {a: 1}, unconstrained Expected field a to be null, but found integer: 1.
validate({v: null}, {v: ['$EXACT', null]}) refused: Expected field v to be exactly equal to null, but found no value. accepted: {v: null}
validate({}, {a: null}, {meta: {'$EXACT': true}}) {a: null} Value at field a: should equal null.

Why the corpus does not catch these

The omni runner's default flag null: true rewrites every null in the corpus to the string __NULL__. validate's child, one, exact and special sections run that way. Only basic and invalid run with null: false, and neither has a null under a non-command default.

So validate.aon's {data: null, spec: ['$EXACT', null]} -> out: null passes in every port only because of that rewrite. typescript itself refuses a real null there.

A null: false case in validate.aon's basic section, {retries: null} against {retries: 3} plus the map and list variants, would pin the default behaviour for every port, and would fail php today.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions