Skip to content

Commit

Permalink
One-line fix for a minor bug about encoding (gnembon#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
17183248569 authored Jul 21, 2022
1 parent 0f474f3 commit a38cd09
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/carpet/script/language/DataStructures.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ else if (lv.size() == 2)
return (cc, tt) -> ret;
});

expression.addUnaryFunction("encode_b64", v -> StringValue.of(Base64.getEncoder().encodeToString(v.getString().getBytes())));
expression.addUnaryFunction("encode_b64", v -> StringValue.of(Base64.getEncoder().encodeToString(v.getString().getBytes(StandardCharsets.UTF_8))));
expression.addUnaryFunction("decode_b64", v -> {
try {
return StringValue.of(new String(Base64.getDecoder().decode(v.getString()), StandardCharsets.ISO_8859_1));//using this charset cos it's the one used in decoding function
return StringValue.of(new String(Base64.getDecoder().decode(v.getString()), StandardCharsets.UTF_8));
} catch (IllegalArgumentException iae){
throw new ThrowStatement("Invalid b64 string: " + v.getString(), Throwables.B64_ERROR);
}
Expand Down

0 comments on commit a38cd09

Please sign in to comment.