Skip to content

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

Conversation

dmytrokasianenko-outreach
Copy link
Contributor

@dmytrokasianenko-outreach dmytrokasianenko-outreach commented Jun 9, 2022

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, causing fixUnescapedQuotes function to break Content-Type header, making it multipart/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 for IndexQuoted or CountQuoted (analog of strings.Index and strings.Count), if we'll need it the future.


// 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 {
Copy link
Owner

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.

Copy link
Contributor Author

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 runes.

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?

Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 🙂

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.
Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, comment removed

},
{
// Quotes must be escaped via RFC2047 encoding, not just a backslash.
// b through c below must not be treated as a single quoted-run.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, comment removed

@jhillyerd jhillyerd merged commit 48f4e03 into jhillyerd:master Jun 15, 2022
@jhillyerd
Copy link
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants