Skip to content

Commit

Permalink
Percent-encode some more characters
Browse files Browse the repository at this point in the history
  • Loading branch information
prdoyle committed Feb 23, 2023
1 parent ed3964f commit b7347e4
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,24 @@ static <T> Reference<?> enclosingReference(Reference<T> ref) {
};

ENCODER = s->{
// Selective percent-encoding of characters MongoDB doesn't like
// Selective percent-encoding of characters MongoDB doesn't like.
// Standard percent-encoding doesn't handle the period character, which
// we want, so if we're already diverging from the standard, we might
// as well do something that suits our needs.
// Good to stay compatible with standard percent-DEcoding, though.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); ) {
int cp = s.codePointAt(i);
switch (cp) {
case '%': // For percent-encoding
case '$': // MongoDB treats these specially
case '.': // MongoDB separator for dotted field names
case 0: // Can MongoDB handle nulls? Probably. Do we want to find out? Not really.
case '|': // (These are reserved for internal use)
case '!':
case '~':
case '[':
case ']':
appendPercentEncoded(sb, cp);
break;
default:
Expand Down

0 comments on commit b7347e4

Please sign in to comment.