Skip to content

Commit

Permalink
fix: issue with empty or null value
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Feb 2, 2023
1 parent 15e3300 commit d8acacc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean isDownloaded() {
return (
!this.isBuiltin() &&
this.downloaded != null &&
!this.downloaded.equals("") &&
!this.downloaded.isEmpty() &&
!this.isDeleted()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void finishDownload(
checksum
);
this.saveBundleInfo(id, info);
if (!checksumRes.equals("") && !checksumRes.equals(checksum)) {
if (checksumRes != null && !checksumRes.isEmpty() && !checksumRes.equals(checksum)) {
Log.e(
CapacitorUpdater.TAG,
"Error checksum " + info.getChecksum() + " " + checksum
Expand Down Expand Up @@ -463,7 +463,8 @@ private String getChecksum(File file) throws IOException {

private void decryptFile(final File file, final String ivSessionKey)
throws IOException {
if (this.privateKey.equals("") || ivSessionKey.equals("")) {
// (str != null && !str.isEmpty())
if (this.privateKey == null || this.privateKey.isEmpty() || ivSessionKey == null || ivSessionKey.isEmpty()) {
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ public void onActivityStopped(@NonNull final Activity activity) {
for (DelayCondition delayCondition : delayConditionList) {
if (delayCondition.getKind().toString().equals("background")) {
String value = delayCondition.getValue();
backgroundValue = (value != null || !value.equals("")) ? value : "0";
backgroundValue = (value != null && !value.isEmpty()) ? value : "0";
}
}
if (backgroundValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ private void publishResults(
String error
) {
Intent intent = new Intent(NOTIFICATION);
if (!dest.equals("")) {
if (dest != null && !dest.isEmpty()) {
intent.putExtra(FILEDEST, dest);
}
if (!error.equals("")) {
if (error != null && !error.isEmpty()) {
intent.putExtra(ERROR, error);
}
intent.putExtra(ID, id);
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/BundleInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import Foundation
}

public func getVersionName() -> String {
return self.version == "" ? BundleInfo.ID_BUILTIN : self.version
return (self.version ?? "").isEmpty ? BundleInfo.ID_BUILTIN : self.version
}

public func setVersionName(version: String) -> BundleInfo {
Expand Down
12 changes: 6 additions & 6 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ extension CustomError: LocalizedError {
}

private func decryptFile(filePath: URL, sessionKey: String) throws {
if self.privateKey == "" || sessionKey == "" {
if (self.privateKey ?? "").isEmpty || (sessionKey ?? "").isEmpty {
print("\(self.TAG) Cannot found privateKey or sessionKey")
return
}
Expand Down Expand Up @@ -437,7 +437,7 @@ extension CustomError: LocalizedError {
private func setCurrentBundle(bundle: String) {
UserDefaults.standard.set(bundle, forKey: self.CAP_SERVER_PATH)
UserDefaults.standard.synchronize()
print("\(self.TAG) Current bundle set to: \(bundle == "" ? BundleInfo.ID_BUILTIN : bundle)")
print("\(self.TAG) Current bundle set to: \((bundle ?? "").isEmpty ? BundleInfo.ID_BUILTIN : bundle)")
}

public func download(url: URL, version: String, sessionKey: String) throws -> BundleInfo {
Expand Down Expand Up @@ -625,7 +625,7 @@ extension CustomError: LocalizedError {

func setChannel(channel: String) -> SetChannel {
let setChannel: SetChannel = SetChannel()
if self.channelUrl == "" {
if (self.channelUrl ?? "").isEmpty {
print("\(self.TAG) Channel URL is not set")
setChannel.message = "Channel URL is not set"
setChannel.error = "missing_config"
Expand Down Expand Up @@ -662,7 +662,7 @@ extension CustomError: LocalizedError {

func getChannel() -> GetChannel {
let getChannel: GetChannel = GetChannel()
if self.channelUrl == "" {
if (self.channelUrl ?? "").isEmpty {
print("\(self.TAG) Channel URL is not set")
getChannel.message = "Channel URL is not set"
getChannel.error = "missing_config"
Expand Down Expand Up @@ -702,7 +702,7 @@ extension CustomError: LocalizedError {
}

func sendStats(action: String, versionName: String) {
if self.statsUrl == "" {
if (self.statsUrl ?? "").isEmpty {
return
}
var parameters: InfoObject = self.createInfoObject()
Expand Down Expand Up @@ -797,7 +797,7 @@ extension CustomError: LocalizedError {
guard let bundlePath: String = UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) else {
return BundleInfo.ID_BUILTIN
}
if bundlePath == "" {
if (bundlePath ?? "").isEmpty {
return BundleInfo.ID_BUILTIN
}
let bundleID: String = bundlePath.components(separatedBy: "/").last ?? bundlePath
Expand Down

0 comments on commit d8acacc

Please sign in to comment.