Skip to content

Commit

Permalink
Merge pull request #404 from crowdin/fix-croql
Browse files Browse the repository at this point in the history
Encode croql parameter
  • Loading branch information
andrii-bodnar authored Oct 27, 2021
2 parents 6f479a2 + 6af8289 commit 79abc02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.commands.functionality.ProjectFilesUtils;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.utils.Utils;
import com.crowdin.cli.utils.console.ConsoleSpinner;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.sourcefiles.model.Branch;
Expand Down Expand Up @@ -61,19 +62,15 @@ public void act(Outputter out, ProjectProperties pb, ProjectClient client) {
.stream()
.collect(Collectors.toMap((entry) -> entry.getValue().getId(), Map.Entry::getKey));

String encodedFilter;
try {
encodedFilter = (filter != null) ? URLEncoder.encode(filter, StandardCharsets.UTF_8.toString()) : null;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
String encodedFilter = filter != null ? Utils.encodeURL(filter) : null;
String encodedCroql = croql != null ? Utils.encodeURL(croql) : null;

List<SourceString> sourceStrings;
if (StringUtils.isEmpty(file)) {
sourceStrings = client.listSourceString(null, branchId, null, encodedFilter, croql);
sourceStrings = client.listSourceString(null, branchId, null, encodedFilter, encodedCroql);
} else {
if (paths.containsKey(file)) {
sourceStrings = client.listSourceString(paths.get(file).getId(), branchId, null, encodedFilter, croql);
sourceStrings = client.listSourceString(paths.get(file).getId(), branchId, null, encodedFilter, encodedCroql);
} else {
throw new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.file_not_exists"), file));
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/crowdin/cli/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.crowdin.cli.utils;

import lombok.NonNull;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -153,4 +157,12 @@ public static Optional<Pair<String, String>> proxyCredentials() {
return Optional.empty();
}
}

public static String encodeURL(@NonNull String toEncode) {
try {
return URLEncoder.encode(toEncode, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 79abc02

Please sign in to comment.