I'm trying to query users by displayName, but I have trouble escaping single quote when sending the request by both C# SDK and Graph Explorer.
Update: It's not clear in the example, the search term I have trouble with is I'
Example query:
https://graph.microsoft.com/v1.0/users?$filter=startsWith(displayName,'I%27') results in
Status Code: 400
{
"error": {
"code": "BadRequest",
"message": "There is an unterminated string literal at position 28 in 'startsWith(displayName,'I'')'.",
// snip
}
}
I tried all sorts of escaping, with backslashes, double quotes, %2527 instead of the quote, nothing works. What's the proper way to query with a quote?
https://graph.microsoft.com/v1.0/users?$filter=startsWith(displayName,'I''')
Based on http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/abnf/odata-abnf-construction-rules.txt:
SQUOTE-in-string = SQUOTE SQUOTE ; two consecutive single quotes
represent one within a string literal
Related
I am trying to create a Lexer/Parser with ANTLR that can parse plain text with 'tags' scattered inbetween.
These tags are denoted by opening ({) and closing (}) brackets and they represent Java objects that can evaluate to a string, that is then replaced in the original input to create a dynamic template of sorts.
Here is an example:
{player:name} says hi!
The {player:name} should be replaced by the name of the player and result in the output i.e. Mark says hi! for the player named Mark.
Now I can recognize and parse the tags just fine, what I have problems with is the text that comes after.
This is the grammar I use:
grammar : content+
content : tag
| literal
;
tag : player_tag
| <...>
| <other kinds of tags, not important for this example>
| <...>
;
player_tag : BRACKET_OPEN player_identifier SEMICOLON player_string_parameter BRACKET_CLOSE ;
player_string_parameter : NAME
| <...>
;
player_identifier : PLAYER ;
literal : NUMBER
| STRING
;
BRACKET_OPEN : '{';
BRACKET_CLOSE : '}';
PLAYER : 'player'
NAME : 'name'
NUMBER : <...>
STRING : (.+)? /* <- THIS IS THE PROBLEMATIC PART !*/
Now this STRING Lexer definition should match anything that is not an empty string but the problem is that it is too greedy and then also consumes the { } bracket tokens needed for the tag rule.
I have tried setting it to ~[{}]+ which is supposed to match anything that does not include the { } brackets but that screws with the tag parsing which I don't understand either.
I could set it to something like [ a-zA-Z0-9!"ยง$%&/()= etc...]+ but I really don't want to restrict it to parse only characters available on the british keyboard (German umlaute or French accents and all other special characters other languages have must to work!)
The only thing that somewhat works though I really dislike it is to force strings to have a prefix and a suffix like so:
STRING : '\'' ~[}{]+ '\'' ;
This forces me to alter the form from "{player:name} says hi!" to "{player:name}' says hi!'" and I really desperately want to avoid such restrictions because I would then have to account for literal ' characters in the string itself and it's just ugly to work with.
The two solutions I have in mind are the following:
- Is there any way to match any number of characters that has not been matched by the lexer as a STRING token and pass it to the parser? That way I could match all the tags and say the rest of the input is just plain text, give it back to me as a STRING token or whatever...
- Does ANTLR support lookahead and lookbehind regex expressions with which I could match any number of characters before the first '{', after the last '}' and anything inbetween '}' and '{' ?
I have tried
STRING : (?<=})(.+)?(?={) ;
but I can't seem to get the syntax right because that won't compile at all, which leads me to believe that ANTLR does not support lookahead and lookbehind syntax, but I could not find a definitive answer on the internet to that question.
Any advice on what to do?
Antlr does not support lookahead or lookbehind. It does support non-greedy wildcard matches, but only when the .* non-greedy wildcard is followed in the rule with the termination sequence (which, as you say, is also contained in the match, although you could push it back into the input stream).
So ~[{}]* is correct. But there's a little problem: lexer rules are (normally) always active. So that lexer rule will be active inside the braces as well, which means that it will swallow the entire contents between the braces (unless there are nested braces or braces inside quotes or some such, and that's even worse).
So you need to define different lexical contents, called "lexical modes" in Antlr. There's a publically viewable example in the Antlr Definitive Reference, which shows a solution to a very similar problem: parsing HTML.
I want to parse a GraphQL document using Dart PetitParser.
To be able to support BlockString (multi-line string) I'm looking for a way to get
from
"""
abc
\"""
def
"""
this part out
abc
\"""
def
Full syntax https://facebook.github.io/graphql/draft/#sec-String-Value
I am on a mobile Phone and I don't have a computer to test, but something along these lines should work:
string('"""') & (string(r'\"""') | any()).starLazy(string('"""')) & string('"""')
This parses the triple quotes, followed by any sequence of the escaped triple quotes or other characters, until we reach the ending triple quotes. Possibly you want to also add a .flatten() to the inner part to get a plain string as return value.
I'm trying to create a regular expression string that will capture the data between the opening and closing [] brackets and include the brackets from the following data:
data: [{"LOTS OF DATA}],
datatype: "local",
So far I'm using a regEx string "data:(.*)" and this is returning:
[{"LOTS OF DATA}],
This is almost correct but includes the ',' and the reason this is working is because theres a newline or carriage return before 'datatype:' So I have two questions:
How do I capture all characters including the newline & carriage return?
How do I match the ', datatype:' string. The issue with this is that I cannot guarantee the character type and number of characters between the ',' and 'datatype:' string, I need a wild card? The regEx string would look something like "data:(.*),???datatype:" where ??? is the wildcard?
Thanks for your help, this will be used within an iOS application.
data:\s*\[([^\[\]]*)\]\s*,\s*datatype:
This implies that no square brackets may occur within LOTS OF DATA.
You could even spare the trailing 'datatype:' match.
Should LOTS OF DATA contains square brackets you would have to come up with a more precise specification of its content.
I need to generate things like"
F||;||(,t,t)".
I try parse("F__||;|(,t,t)"). Maple returns "Error, incorrect syntax in parse: ; unexpected (near 6th character of parsed string)"
Is there any way to get this F||;||(,t,t)"?
To create names with special characters, you need to use single back quotes (also known as accent grave), which is the character under escape on most US keyboards.
parse("`F__||;||`(``,t,t)");
I have a text input for a search field where the string is then passed to an EntityQuery. When ever the query includes a single quote I get a message like the following:
There is an unterminated string literal at position 39 in 'substringof(O'Malley,FirstName) eq true'.
It even happens when just hard coding the query like this:
var query = breeze.EntityQuery
.from("Users")
.expand("GroupUsers.Group")
.where("lastName", "contains","O'Malley")
.skip(skipAmt)
.take(pageSize)
.inlineCount(true);
I've tried escaping the single quote by doing double single quotes or doing \' and it still comes back with an error. This also happens similarly with double quotes. What is the proper way to escape the string literal characters?
I can't repro this. You should be able to escape a single ' by simply doubling it. For example, the following query works without a problem on v 1.2.8.
var q = EntityQuery.from("Employees")
.where("lastName", "contains", "O''Malley");
Does the problem still occur if you 'simplify' the query down to just the where 'clause'?