-
Notifications
You must be signed in to change notification settings - Fork 110
fix(mediatype): quoted semicolon #256
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
fix(mediatype): quoted semicolon #256
Conversation
internal/stringutil/find.go
Outdated
|
||
// FindQuoted returns the indexes of the instance of v in s, or empty slice if v is not present in s. | ||
// It ignores v present inside quoted runs. | ||
func FindQuoted(s string, v rune, quote rune) []int { |
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.
If I am understanding it's operation correctly, should this be called FindUnquoted? Similar comment on the quotedIndices
var name.
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.
That's true, it sounds like it would find all quoted rune
s.
The idea was to have the same naming convention. Before this PR, there was a function SplitQuoted
, it works like strings.Split
, but respects quotes. That's why I named this one FindQuoted
, it finds rune
, but respects quotes.
I can rename all functions to FindUnquoted
, SplitUnquoted
and SplitAfterUnqioted
, WDYT?
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.
I think renaming everything to Unquoted would make sense
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.
fixed 🙂
internal/stringutil/split_test.go
Outdated
input: `"a;b";"c;d`, | ||
want: []string{`"a`, `b"`, `"c`, `d`}, | ||
want: []string{`"a;b"`, `"c`, `d`}, | ||
}, | ||
{ | ||
// Quotes must be escaped via RFC2047 encoding, not just a backslash. | ||
// b through c below must not be treated as a single quoted-run. |
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.
I think this comment is now out of date, as we are treating b-c as single quoted run. I am a little concerned that we are changing something that is noted as "must" in the comment, but given mediatype tests are still passing, I guess we will roll with it.
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.
yeah, I was not sure about its original behavior, because it is possible to have Content-Type: application/rtf; charset=utf-8; name="\"žába\".jpg"
(in this test), which means quotes can be escaped
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.
thanks, comment removed
internal/stringutil/split_test.go
Outdated
}, | ||
{ | ||
// Quotes must be escaped via RFC2047 encoding, not just a backslash. | ||
// b through c below must not be treated as a single quoted-run. |
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.
ditto
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.
thanks, comment removed
Thank you! |
This PR fixes splitting of Content-Type header, when parameter has semicolon inside quoted text
;
, e.g.multipart/mixed; boundary="aaa;bbb;ccc"
. Previously, it was splitting wrongly, causingfixUnescapedQuotes
function to break Content-Type header, making itmultipart/mixed; boundary=""
Introduce new
FindQuoted
function. Reasoning: because for the splitting we still need to go through whole string, we can as well find all points where we need split. And then, use it forIndexQuoted
orCountQuoted
(analog ofstrings.Index
andstrings.Count
), if we'll need it the future.