HarshMehta112 commented on code in PR #3416:
URL: https://github.com/apache/dubbo-go/pull/3416#discussion_r3409434108
##########
protocol/triple/triple_protocol/protocol.go:
##########
@@ -367,3 +379,41 @@ func canonicalizeContentTypeSlow(contentType string)
string {
}
return mime.FormatMediaType(base, params)
}
+
+// isSimpleMediaType reports whether s is a well-formed, already-lowercase
media
+// type without parameters: letters a-z, '.', '+', '-', exactly one '/'.
+func isSimpleMediaType(s string) bool {
+ slashes := 0
+ for i := 0; i < len(s); i++ {
+ c := s[i]
+ switch {
+ case c >= 'a' && c <= 'z':
+ case c == '.' || c == '+' || c == '-':
+ case c == '/':
+ slashes++
+ default:
+ return false
+ }
+ }
+ return slashes == 1
+}
Review Comment:
Good catch. Fixed — `isLowercaseMediaType` now checks `slash > 0` and `slash
< len(s)-1`, so both sides of `/` must be non-empty. Malformed inputs like
`/json; charset=UTF-8` and `application/; charset=UTF-8` now fall through to
`canonicalizeContentTypeSlow` and return unchanged. Added test cases for both.
Also took the opportunity to split the fast-path logic into
`canonicalizeContentTypeFast` as suggested and renamed helpers for clarity
(`isLowercaseToken`, `isSimpleCharsetToken`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]