fix: parse the mime metadata when do get/head object#2106
Conversation
fix: parse the mime metadata when do get/head object
There was a problem hiding this comment.
Pull Request Overview
This PR enhances metadata handling by decoding MIME-encoded metadata values for GET/HEAD operations and adds targeted unit tests.
- Decode Q-/B-encoded values for both
X-Minio-Meta-andX-Amz-Meta-headers inextractObjMetadata. - Add
TestExtractObjMetadatato cover plain, Q-encoded, and B-encoded metadata scenarios.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| utils.go | Import mime and extend extractObjMetadata to detect and decode MIME word–encoded metadata. |
| utils_test.go | Add TestExtractObjMetadata with cases for unencoded, Q-encoded, and B-encoded metadata values. |
Comments suppressed due to low confidence (1)
utils_test.go:493
- Consider adding a corresponding test case for the AWS-style
X-Amz-Meta-prefix to ensure that the same decoding logic also applies correctly to AWS metadata headers.
"X-Minio-Meta-Test": []string{mime.QEncoding.Encode("UTF-8", "öha, das")},
| } | ||
| found = true | ||
| if len(v) == 1 && (prefix == "X-Amz-Meta-" || prefix == "X-Minio-Meta-") { | ||
| i := strings.Index(v[0], "=?") |
There was a problem hiding this comment.
Can this be other than at the start of the value? Maybe just check prefix?
There was a problem hiding this comment.
Only metadata have that string
There was a problem hiding this comment.
I am thinking of i := strings.Index(v[0], "=?") vs if strings.HasPrefix(v[0], "=?") - so it will not be picked up from within the middle of values.
There was a problem hiding this comment.
// DecodeHeader decodes all encoded-words of the given string. It returns an
// error if and only if [WordDecoder.CharsetReader] of d returns an error.
func (d *WordDecoder) DecodeHeader(header string) (string, error) {
// If there is no encoded-word, returns before creating a buffer.
i := strings.Index(header, "=?")
if i == -1 {
return header, nil
}And I have test the string such as Test=?utf-8?q?=C3=B6?= can be deocded @klauspost
There was a problem hiding this comment.
@jiuker Is that valid encoding? That is why I am asking.
If it is sent as Test=?utf-8?q?=C3=B6?= the client would expect to get it back like this and should return it as-is. We need to be roundtrip safe.
There was a problem hiding this comment.
@klauspost Yesh. I think HavePrefix should be better. Could you take a look here.
support mutil val
be706a7 to
615fa50
Compare
|
@klauspost PTAL |
fix: parse the mime metadata when do get/head object
will work with minio/minio#21282