I'm attempting to post some data into Firebase (relative part of the URL is /messages.json). The following request content:
{"gsx$enddate":"sometime"}
Gives the following error:
Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names.
This is valid JSON however. What am I doing wrong?
It's supposed to be a valid JSON but it seems like it's a limitation for FireBase
From FireBase Documentation:
Character Set Limitations
Note that URLs used to construct Firebase references may contain any
unicode characters except:
. (period)
$ (dollar sign)
[ (left square bracket)
] (right square bracket)
# (hash or pound sign)
/ (forward slash)
Related
I am using Gremlin java and I found GroovyTranslator adds additional \ before $ sign,
and this causes query failing to execute on remote server.
GraphTraversal traversal = graph.addV().property("amount", "$1");
System.out.println(GroovyTranslator.of("g").translate(traversal.asAdmin().getBytecode()));
Translated result:
g.addV().property("amount","\$1")
If this is issue with GroovyTranslator, i can replace \$ with $, but I am not sure if more special characters will have this issue.
This fails because of backslash, but what if some property value want to use backslash?
From what I see, use backslash will always fail.
I suppose following should work but it doesn't:
curl -X POST -d '{"gremlin":"g.V().has(\"key\",\"\\$\")"}' ...
In Groovy the dollar sign has special meaning if you are using Groovy Strings (GStrings). It is used to indicate interpolation should occur as in :
gremlin> a=3
==>3
gremlin> "The number is $a"
==>The number is 3
If the server you are connecting to uses Groovy as-is to parse the query then the backslash is needed. If the server does not use Groovy as-is then you will need to remove the backslash.
There are a few other things to be aware of with GroovyTranslator. When it generates literal numbers it puts a cast such as (int) 3 into the query. You may need to also remove these depending on the back end graph database you are connecting to.
I am wondering what kind of characters are allowed in the push key. Does it generate also a symbol underscore(_)? I always get a push key with letters with -.
Push keys use a modified Base64 alphabet:
-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
They are comprised of a timestamp and a random value. The algorithm is described here.
With Firebase keys in general, there is a small set of illegal characters and they are listed in this answer:
Character Set Limitations
Note that URLs used to construct Firebase references may contain any
unicode characters except:
. (period)
$ (dollar sign)
[ (left square bracket)
] (right square bracket)
# (hash or pound sign)
/ (forward slash)
I have a URL like that: localhost:8080/demo/
And when I call localhost:8080/demo/''''''''' It working fine.
But when I try with localhost:8080/demo/;;; It not working and return HTTP code 404 Not Found.
I tried with few special character # % \ ? / , it returned 400 too.
Anyone can explain it for me?
Thank you so much!
These special characters are not directly allowed in URLs,
because they have special meanings there.
For example:
/ is separator within the path,
? marks the query-part of an URL,
# marks a page-internal link,
etc.
Quoted from Wikipedia: Percent-encoding reserved characters:
When a character from the reserved set (a "reserved character")
has special meaning (a "reserved purpose") in a certain context,
and a URI scheme says that it is necessary to use that character
for some other purpose, then the character must be percent-encoded.
Percent-encoding a reserved character involves converting the
character to its corresponding byte value in ASCII and then
representing that value as a pair of hexadecimal digits. The digits,
preceded by a percent sign (%) which is used as an escape character,
are then used in the URI in place of the reserved character.
For example: ; is a reserved character. Therefore, when ; shall occur
in an URL but without having its special meaning, then it needs to be
replaced by %3B as defined here
I am wondering what kind of characters are allowed in the push key. Does it generate also a symbol underscore(_)? I always get a push key with letters with -.
Push keys use a modified Base64 alphabet:
-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
They are comprised of a timestamp and a random value. The algorithm is described here.
With Firebase keys in general, there is a small set of illegal characters and they are listed in this answer:
Character Set Limitations
Note that URLs used to construct Firebase references may contain any
unicode characters except:
. (period)
$ (dollar sign)
[ (left square bracket)
] (right square bracket)
# (hash or pound sign)
/ (forward slash)
I want to restrict few file types format and allow all others in regular expression validation expression. What i have try is specify some allowed and some restricted file types but i want to specify restricted file types and allow all others type to be uploaded.
I am using regular expression with asp.net file upload control. My regular expression looks like this right now
^.*\.(csv|xlsx|xls|doc|docx|pdf|txt|zip|(?!exe)|(?!bat)|(?!msi))$
Its working fine and restricting exe bat and msi but i want to allow all other file formats
Use a negative lookbehind:
/^.*(?<!\.(exe|bat|msi))$/i
The negative lookaheads you're using aren't helping you. At all. They're trivially true because you're trying to match them at the end of the string, and lookarounds don't consume anything, so the last position in the string can't have exe or bat after it.
A step by step explanation, for posterity's sake:
^
Match the start of the string, as I'm sure you know.
.*
consume the whole string.
(?<! ... )
Look back and make sure we haven't consumed....
\.
A literal dot, followed by...
(exe|bat|msi)
any of our verbotten file types.
$
then match the end of the string.
I also chose to make it case insensitive.
Edit, for js:
/^(?:(?!\.(exe|bat|msi)$).)*/i
Moar different explanation:
^
Top of string
(
Start group
.
Arbitrary Character
(?!...)
Negative lookahead. Not followed by:
\.
Literal dot.
(exe|bat|msi)
Forbidden File types.
$
End of string
)*
Close group and match that an arbitrary number of times.