Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public Object execute( final Object iThis, final Identifiable iCurrentRecord, fi

if (SQLFunctionEncode.FORMAT_BASE64.equalsIgnoreCase(format)) {
return Base64.getDecoder().decode(candidate);
} else if (SQLFunctionEncode.FORMAT_BASE64URL.equalsIgnoreCase(format)) {
final int padding = (candidate.length() % 4 == 2 ? 2 : (candidate.length() % 4 == 3 ? 1 : 0));
return Base64.getDecoder().decode(candidate.replace('-','+').replace('_','/') + "=".repeat(padding));
} else {
throw new CommandSQLParsingException("Unknown format :" + format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
*/
public class SQLFunctionEncode extends SQLFunctionAbstract {

public static final String NAME = "encode";
public static final String FORMAT_BASE64 = "base64";
public static final String NAME = "encode";
public static final String FORMAT_BASE64 = "base64";
public static final String FORMAT_BASE64URL = "base64url";

/**
* Get the date at construction to have the same date for all the iteration.
Expand All @@ -54,6 +55,8 @@ public Object execute(final Object iThis, final Identifiable iCurrentRecord, fin
byte[] data = null;
if (candidate instanceof byte[]) {
data = (byte[]) candidate;
} else if (candidate instanceof String) {
data = ((String) candidate).getBytes();
} else if (candidate instanceof RID) {
final Record rec = ((RID) candidate).getRecord();
if (rec instanceof Binary) {
Expand All @@ -67,6 +70,8 @@ public Object execute(final Object iThis, final Identifiable iCurrentRecord, fin

if (FORMAT_BASE64.equalsIgnoreCase(format)) {
return Base64.getEncoder().encodeToString(data);
} else if (FORMAT_BASE64URL.equalsIgnoreCase(format)) {
return Base64.getEncoder().withoutPadding().encodeToString(data).replace('+','-').replace('/','_');
} else {
throw new CommandSQLParsingException("Unknown format :" + format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public SQLMethodAsString() {

@Override
public Object execute(final Object iThis, final Identifiable iCurrentRecord, final CommandContext iContext, Object ioResult, final Object[] iParams) {
ioResult = ioResult != null ? ioResult.toString() : null;
return ioResult;
if (ioResult == null) {
return null;
} else if (ioResult instanceof byte[]) {
return new String((byte[]) ioResult);
} else {
return ioResult.toString();
}
}
}