Skip to content

Commit 929fd4b

Browse files
committed
Adding the changes.
1 parent 1f2fbe1 commit 929fd4b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import java.math.BigDecimal;
132132
import java.net.URLEncoder;
133133
import java.nio.charset.Charset;
134+
import java.nio.charset.CharsetEncoder;
134135
import java.nio.charset.StandardCharsets;
135136
import java.nio.file.Files;
136137
import java.nio.file.Path;
@@ -3569,13 +3570,21 @@ public <R extends AbstractReadHandle> R postBulkDocuments(
35693570
mimeType = defaultFormat.getDefaultMimetype();
35703571
}
35713572
headers.add(HEADER_CONTENT_TYPE, mimeType);
3572-
String disposition = null;
3573-
try {
3574-
disposition = DISPOSITION_TYPE_ATTACHMENT + "; " +
3575-
DISPOSITION_PARAM_FILENAME + "*=UTF-8''" + URLEncoder.encode(write.getUri(), "UTF-8") + contentDispositionTemporal;
3576-
} catch (Exception ex) {
3577-
ex.printStackTrace();
3578-
}
3573+
String disposition = null;
3574+
CharsetEncoder asciiEncoder = java.nio.charset.StandardCharsets.US_ASCII.newEncoder();
3575+
if(asciiEncoder.canEncode(write.getUri())) {
3576+
disposition = DISPOSITION_TYPE_ATTACHMENT + "; " +
3577+
DISPOSITION_PARAM_FILENAME + "=" + escapeContentDispositionFilename(write.getUri()) + contentDispositionTemporal;
3578+
}
3579+
else {
3580+
try {
3581+
disposition = DISPOSITION_TYPE_ATTACHMENT + "; " +
3582+
DISPOSITION_PARAM_FILENAME + "*=UTF-8''" + URLEncoder.encode(write.getUri(), "UTF-8") + contentDispositionTemporal;
3583+
} catch (Exception ex) {
3584+
throw new IllegalArgumentException("Uri cannot be accepted");
3585+
}
3586+
}
3587+
asciiEncoder.reset();
35793588
headers.add(HEADER_CONTENT_DISPOSITION, disposition);
35803589
headerList.add(headers);
35813590
writeHandles.add(write.getContent());

0 commit comments

Comments
 (0)