-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-27077 Added fix for invalid header for empty doc #1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,9 @@ | |
| import jakarta.mail.BodyPart; | ||
| import jakarta.mail.Header; | ||
| import jakarta.mail.MessagingException; | ||
| import jakarta.mail.internet.ContentDisposition; | ||
| import jakarta.mail.internet.MimeMultipart; | ||
| import jakarta.mail.internet.ParseException; | ||
| import jakarta.mail.util.ByteArrayDataSource; | ||
| import jakarta.xml.bind.DatatypeConverter; | ||
| import okhttp3.*; | ||
|
|
@@ -1808,16 +1810,50 @@ static private long getHeaderLength(String length) { | |
|
|
||
| static private String getHeaderUri(BodyPart part) { | ||
| try { | ||
| if (part != null) { | ||
| return part.getFileName(); | ||
| if (part == null) { | ||
| return null; | ||
| } | ||
| // if it's not found, just return null | ||
|
|
||
| try { | ||
| String filename = part.getFileName(); | ||
| if (filename != null) { | ||
| return filename; | ||
| } | ||
| } catch (ParseException e) { | ||
| // Jakarta Mail's parser failed due to malformed Content-Disposition header. | ||
| // Check if MarkLogic sent a malformed "format=" parameter at the end, which violates RFC 2183. | ||
| String contentDisposition = getHeader(part, "Content-Disposition"); | ||
| if (contentDisposition != null && contentDisposition.matches(".*;\\s*format\\s*=\\s*$")) { | ||
| // Remove the trailing "; format=" to fix the malformed header | ||
| String cleaned = contentDisposition.replaceFirst(";\\s*format\\s*=\\s*$", "").trim(); | ||
| logger.debug("Removed trailing 'format=' from malformed Content-Disposition header: {} -> {}", contentDisposition, cleaned); | ||
| return extractFilenameFromContentDisposition(cleaned); | ||
| } | ||
| throw e; | ||
| } | ||
|
|
||
| return null; | ||
| } catch (MessagingException e) { | ||
| throw new MarkLogicIOException(e); | ||
| } | ||
| } | ||
|
|
||
| static private String extractFilenameFromContentDisposition(String contentDisposition) { | ||
| if (contentDisposition == null) { | ||
| return null; | ||
| } | ||
| try { | ||
| // Use Jakarta Mail's ContentDisposition parser to extract the filename parameter. This is the class | ||
| // that throws an error when "format=" exists in the value, but that has been removed already. | ||
| ContentDisposition cd = new ContentDisposition(contentDisposition); | ||
| return cd.getParameter("filename"); | ||
| } catch (ParseException e) { | ||
| logger.warn("Failed to parse cleaned Content-Disposition header: {}; cause: {}", | ||
| contentDisposition, e.getMessage()); | ||
| return null; | ||
| } | ||
| } | ||
|
Comment on lines
+1841
to
+1855
|
||
|
|
||
| static private void updateVersion(DocumentDescriptor descriptor, Headers headers) { | ||
| updateVersion(descriptor, extractVersion(headers.get(HEADER_ETAG))); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
ParseExceptionrecovery path is important behavior (it changes failure into a best-effort filename extraction). Add a focused test that reproduces a malformedContent-Dispositionending in; format=and asserts thatgetHeaderUrireturns the expected filename (and does not throw).