Skip to content

Commit

Permalink
fix: check for empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed May 9, 2022
1 parent d403c4b commit 12523f9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cpp/BaseCoderHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Value BaseCoderHostObject::get(Runtime& runtime, const PropNameID& propNameId) {
auto algorithm = arguments[1].asObject(runtime).getProperty(runtime, "algorithm").toString(runtime).utf8(runtime);
auto stringToEncode = arguments[0].asString(runtime).utf8(runtime);

if (stringToEncode.length() == 0) {
throw JSError(runtime, "[react-native-jsi-base-coder] The `stringToEncode` cannot be an empty string.");
}

string result;

if (algorithm == "base64Rfc4648") {
Expand Down Expand Up @@ -106,7 +110,7 @@ Value BaseCoderHostObject::get(Runtime& runtime, const PropNameID& propNameId) {
auto bytesToDecode = arguments[0].asString(runtime).utf8(runtime);

if (bytesToDecode.length() == 0) {
throw JSError(runtime, "[react-native-jsi-base-coder] The `bytesToDecode` argument is an empty string.");
throw JSError(runtime, "[react-native-jsi-base-coder] The `bytesToDecode` cannot be an empty string.");
}

vector<unsigned char> result;
Expand Down

0 comments on commit 12523f9

Please sign in to comment.