Skip to content

Commit cb7ed8e

Browse files
cziberpvclaude
andcommitted
fix: regenerate feign-hc5 sample with updated ApiResponseDecoder
The feign-hc5 sample was missed during the second commit's regeneration because setTemplateDir("feign") overrides the filesystem templateDir from the config, causing the generator to use embedded JAR resources. After rebuilding the JAR with the updated mustache template, the feign-hc5 sample now matches feign and feign-no-nullable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0150317 commit cb7ed8e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

samples/client/petstore/java/feign-hc5/src/main/java/org/openapitools/client/ApiResponseDecoder.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.reflect.ParameterizedType;
2525
import java.lang.reflect.Type;
2626
import java.nio.file.Files;
27+
import java.nio.file.Paths;
2728
import java.nio.file.StandardCopyOption;
2829
import java.util.Collection;
2930
import java.util.Collections;
@@ -36,7 +37,7 @@
3637
public class ApiResponseDecoder extends JacksonDecoder {
3738

3839
private static final Pattern FILENAME_PATTERN =
39-
Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
40+
Pattern.compile("filename=\"([^\"]+)\"|filename=([^\\s;]+)");
4041

4142
public ApiResponseDecoder(ObjectMapper mapper) {
4243
super(mapper);
@@ -69,6 +70,9 @@ private boolean isBinaryType(Type type) {
6970

7071
private Object decodeBinary(Response response, Type type) throws IOException {
7172
Class<?> raw = Types.getRawType(type);
73+
if (response.body() == null) {
74+
return null;
75+
}
7276
if (byte[].class.isAssignableFrom(raw)) {
7377
return response.body().asInputStream().readAllBytes();
7478
}
@@ -82,8 +86,10 @@ private File downloadToTempFile(Response response) throws IOException {
8286
String filename = extractFilename(response);
8387
File file;
8488
if (filename != null) {
89+
// Sanitize: strip path components to prevent path traversal
90+
String safeName = Paths.get(filename).getFileName().toString();
8591
java.nio.file.Path tempDir = Files.createTempDirectory("feign-download");
86-
file = Files.createFile(tempDir.resolve(filename)).toFile();
92+
file = Files.createFile(tempDir.resolve(safeName)).toFile();
8793
tempDir.toFile().deleteOnExit();
8894
} else {
8995
file = Files.createTempFile("download-", "").toFile();
@@ -100,7 +106,10 @@ private String extractFilename(Response response) {
100106
if (dispositions == null) return null;
101107
for (String disposition : dispositions) {
102108
Matcher m = FILENAME_PATTERN.matcher(disposition);
103-
if (m.find()) return m.group(1);
109+
if (m.find()) {
110+
// Group 1: quoted filename (may contain spaces), Group 2: unquoted token
111+
return m.group(1) != null ? m.group(1) : m.group(2);
112+
}
104113
}
105114
return null;
106115
}

0 commit comments

Comments
 (0)