Skip to content

Leading spaces in literals #1040

Closed
@sgryphon

Description

@sgryphon

Please read our Contributing Guides before submitting a bug.

DESCRIPTION

A clear and concise description of what the bug is.

The parser for literals does not allow leading spaces (but it does allow trailing spaces). Generally a literal should allow whatever the literal value is.

For example, you might want to search a name field that ends with a particular surname, starting with a space delimiter, e.g. endsWith(name,' Surname'), or a field that contains a space.

Note: There is an existing test, in LegacyFilterParseTests that check a single space in a literal throws an Unexpected whitespace exception, so perhaps this check was intentional. Maybe for an 'equals()' test it is a bit strange to check for a single space (or if the literal is a numeric field), but something like contains(name,' ') to look for something containing a space might make more sense.

STEPS TO REPRODUCE

  1. Test a search filter with a trailing space works, e.g. /webAccounts?filter=startsWith(name,'Given ')
  • The encoded value would be /webAccounts?filter=startsWith(name,%27Given%20%27)
  1. Test a search filter with only a space, e.g. /webAccounts?filter=contains(name,' ')
  • The encoded value would be /webAccounts?filter=contains(name,%27%20%27)

Tests are provided in an example branch:

    [InlineData("filter", "startsWith(name,'GivenName ')", null, "startsWith(name,'GivenName ')")]
    [InlineData("filter", "endsWith(name,' Surname')", null, "endsWith(name,' Surname')")]
    [InlineData("filter", "contains(name,' ')", null, "contains(name,' ')")]

EXPECTED BEHAVIOR

A clear and concise description of what you expected to happen.

Literal values should be treated as is, even if they contain leading whitespace.

ACTUAL BEHAVIOR

A clear and concise description of what happens instead.

Leading whitespace, including a literal of whitespace only, returns the error "Unexpected whitespace.".

VERSIONS USED

  • JsonApiDotNetCore version: v4.2.0 +10 (current head)
  • ASP.NET Core version:
  • Entity Framework Core version:
  • Database provider:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions