String queries in BreezeJS that contain single or double quotes return error - breeze

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'?

Related

Extracting characters between double quotes

In my project, I need to extract some parameters from a settings file.
Below is a section of the line that I am reading, the parameter I need to extract is the Program Prefix.
... ProgramPrefix="" ReceiveTimeout="80000" ...
I need to extract what is between the double quotes for ProgramPrefix. The problem is that in-between these quotes can be any alphanumeric character, symbol, space, or no character at all.
Below is my current solution for extracting any character before the second double-quote, the problem doesn't work for the case of anything being between the double quotes
EOPdefL = string.find(line,"ProgramPostfix=")
EOPdef = string.match(line,'([^"]+)',EOPdefL+16)
When there is nothing in-between the double quotes the output for EOPdef is:
EOPdef = ReceiveTimeout=
I would like EOPdef to just return an empty string if there are no characters.
EOPdef = ""
EDIT: lhf and Piglet provided a working resolution. The character class to capture 0 or more characters in between double quotes is the following:
'"(.-)"'
Implementing this character class into my solution results in the following code:
SOPdefL = string.find(line,"ProgramPrefix=")
SOPdef = string.match(line,'"(.-)"',SOPdefL+14)
one issue with your pattern is that you're trying to match one or more (+) non-doublequote characters. You need to match 0 or more, shortest match (-).
There are multiple ways to achieve this.
Most obvious as lhf already suggested you capture 0 or more characters between double quotes.
str:match('ProgramPrefix="(.-)"')
or you capture a balanced double quote pair and get its contents
str:match('ProgramPrefix=%b""'):sub(2,-2)

Escape quote in Dart Regex

I'm trying to use the regex /^[a-zA-Z0-9_$&+:;=?##|'<>.^*()%!-]+$/ with dart regex. I've seen you can use raw strings. So Ive put the above in between r'' like this:
r'^[a-zA-Z0-9_$&+:;=?##|'<>.^*()%!-]+$' but the ' is messing it up. How do I tell dart this is a special character..
EDIT
I tried this but it doesn't seem to work
static final RegExp _usernameRegExp = RegExp(
r"^[a-zA-Z0-9_$&+:;=?##|'<>.^*()%!-]+$",
);
So I have a TextField with a text controller for a username. A method like this
static bool isValidUsername(String username) {
return (_usernameRegExp.hasMatch(username));
}
I pass the controller.text as the username.
I've a function:
bool get isUserNameValid => (Validators.isValidUsername(userNameTextController.text.trim()));
I can type all the given characters in to the textbook but not '
Your RegExp source contains ', so you can't use that as string delimiter without allowing escapes. It also contains $ so you want to avoid allowing escapes.
You can use " as delimiter instead, so a raw string like r"...".
However, Dart also has "multi-line strings" which are delimited by """ or '''. They can, but do not have to, contain newlines. You can use those for strings containing both ' and ". That allows r'''...'''.
And you can obviously also use escapes for all characters that mean something in a string literal.
So, for your code, that would be one of:
r'''^[\w&+:;=?##|'<>.^*()%!-]+$'''
r"^[\w&+:;=?##|'<>.^*()%!-]+$"
'^[\\w&+:;=?##|\'<>.^*()%!-]+\$'
(I changed A-Za-z0-9$_ to \w, because that's precisely what \w means).
In practice, I'll always use a raw string for regexps. It's far too easy, and far too dangerous, to forget to escape a backslash, so use one of the first two options.
I'd probably escape the - too, making it [....\-] instead of relying on the position to make it non-significant in the character class. It's a fragile design that breaks if yo add one more character at the end of the character class, instead of adding it before the -. It's less fragile if you escape the -.

How to remove ANSI codes from a string?

I am working on string manipulation using LUA and having trouble with the following problem.
Using this as an example of the original data I am given -
"[0;1;36m(Web): You say, "Text here."[0;37m"
I want to keep the string intact except for removing the ANSI codes.
I have been pointed toward using gsub with the LUA pattern matching but I cannot seem to get the pattern correct. I am also unsure how to reference exactly the escape character sent.
text:gsub("[\27\[([\d\;]+)m]", "")
or
text:gsub("%x%[[%d+;+]m", "")
If successful, all I want to be left with, using the above example, would be:
(Web): You say, "Text here."
Your string example is missing the escape character, ASCII 27.
Here's one way:
s = '\x1b[0;1;36m(Web): You say, "Text here."\x1b[0;37m'
s = s:gsub('\x1b%[%d+;%d+;%d+;%d+;%d+m','')
:gsub('\x1b%[%d+;%d+;%d+;%d+m','')
:gsub('\x1b%[%d+;%d+;%d+m','')
:gsub('\x1b%[%d+;%d+m','')
:gsub('\x1b%[%d+m','')
print(s)

Ignore escaped multi-line quotes

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.

Regular Expression Assistance (RegEx)

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.

Resources