Skip to content

Commit

Permalink
KEYCLOAK-12015 Use StandartCharsets in org.keycloak.storage.ldap.idm.…
Browse files Browse the repository at this point in the history
…query.EscapeStrategy (#6474)
  • Loading branch information
Captain1653 authored and mposolda committed Nov 14, 2019
1 parent 4553234 commit b72fe79
Showing 1 changed file with 30 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.keycloak.storage.ldap.idm.query;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
Expand All @@ -30,17 +30,13 @@ public enum EscapeStrategy {

@Override
public String escape(String input) {
try {
StringBuilder output = new StringBuilder();
StringBuilder output = new StringBuilder();

for (byte b : input.getBytes("UTF-8")) {
appendByte(b, output);
}

return output.toString();
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
for (byte b : input.getBytes(StandardCharsets.UTF_8)) {
appendByte(b, output);
}

return output.toString();
}

},
Expand All @@ -52,36 +48,32 @@ public String escape(String input) {

@Override
public String escape(String input) {
try {
StringBuilder output = new StringBuilder();

for (byte b : input.getBytes("UTF-8")) {
switch (b) {
case 0x5c:
output.append("\\5c"); // \
break;
case 0x2a:
output.append("\\2a"); // *
break;
case 0x28:
output.append("\\28"); // (
break;
case 0x29:
output.append("\\29"); // )
break;
case 0x00:
output.append("\\00"); // \u0000
break;
default: {
appendByte(b, output);
}
StringBuilder output = new StringBuilder();

for (byte b : input.getBytes(StandardCharsets.UTF_8)) {
switch (b) {
case 0x5c:
output.append("\\5c"); // \
break;
case 0x2a:
output.append("\\2a"); // *
break;
case 0x28:
output.append("\\28"); // (
break;
case 0x29:
output.append("\\29"); // )
break;
case 0x00:
output.append("\\00"); // \u0000
break;
default: {
appendByte(b, output);
}
}

return output.toString();
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
}

return output.toString();
}

},
Expand All @@ -91,11 +83,7 @@ public String escape(String input) {
@Override
public String escape(String input) {
byte[] bytes;
try {
bytes = input.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
bytes = input.getBytes(StandardCharsets.UTF_8);
return escapeHex(bytes);
}

Expand Down

0 comments on commit b72fe79

Please sign in to comment.