Skip to content
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

Issue with $search query values containing whitespace #10

Closed
awright415 opened this issue Jan 17, 2018 · 3 comments
Closed

Issue with $search query values containing whitespace #10

awright415 opened this issue Jan 17, 2018 · 3 comments

Comments

@awright415
Copy link

When I send a request to the server with a $search query that has whitespace, I get an "Unexpected Character" error, unless there's an AND/OR in between. So, in other words, the request fails on phrase queries and implicit AND queries. Examples:

  • Works: parser.query("$search=foo AND bar")
  • Works: parser.query("$search=\"foo AND bar\"")
  • Does not work: parser.query("$search=foo bar")
  • Does not work: parser.query("$search=\"foo bar\"")
@lazarv
Copy link
Contributor

lazarv commented Jan 18, 2018

Hi @awright415,
the parser is based on the official ABNF and according to it, search phrase and word are:

searchPhrase = quotation-mark 1*qchar-no-AMP-DQUOTE quotation-mark
searchWord   = 1*ALPHA ; Actually: any character from the Unicode categories L or Nl,
                       ; but not the words AND, OR, and NOT

ABNF doesn't allow whitespace in search phrase and encoding needed to work as expected:

parser.query('$search="foo%20bar"')

This works as expected and parsed as a search phrase (because the quotation marks).

{
  position: 8,
  next: 19,
  value: 'foo%20bar',
  type: 'SearchPhrase',
  raw: '"foo%20bar"'
}

@awright415
Copy link
Author

Thanks for the quick response! I got thrown off by this section of the protocol spec, which shows a phrase search example with unescaped whitespace.

Ultimately, the trouble I'm having is running $search queries with odata-v4-server, and perhaps I just submitted the wrong issue on the wrong project. I get 500 responses with the same unexpected character error for those requests (and naturally the whitespace is encoded in the URL).

It looks like inside of processor.ts, the URL is already unescaped before it's sent to the parser. So, in that case, wouldn't the parser be trying to parse a $search query value with unencoded whitespace like examples I provided?

lazarv added a commit that referenced this issue Jan 19, 2018
@lazarv
Copy link
Contributor

lazarv commented Jan 19, 2018

@awright415 - Yes in odata-v4-server the the query is already sent unescaped to the parser. In the 0.1.25 version of odata-v4-parser I modified the lexer to allow whitespace to support unescaped search phrases. Please update from npm and it should be working after.

@lazarv lazarv closed this as completed Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants