-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-12015 Use StandartCharsets in org.keycloak.storage.ldap.idm.…
…query.EscapeStrategy (#6474)
- Loading branch information
1 parent
4553234
commit b72fe79
Showing
1 changed file
with
30 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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(); | ||
} | ||
|
||
}, | ||
|
@@ -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(); | ||
} | ||
|
||
}, | ||
|
@@ -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); | ||
} | ||
|
||
|