Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEYCLOAK-12015 Use StandartCharsets in org.keycloak.storage.ldap.idm.query.EscapeStrategy #6474

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
KEYCLOAK-12015 Use StandartCharsets in org.keycloak.storage.ldap.idm.…
…query.EscapeStrategy
  • Loading branch information
Captain1653 committed Nov 12, 2019
commit 944a8de2fb18609f8f4858767be250636f3233bc
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