-
Notifications
You must be signed in to change notification settings - Fork 38k
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
SPR-17459 Catering for comma being part of the media/mime type as double quoted #2010
Conversation
spring-web/src/main/java/org/springframework/http/MediaType.java
Outdated
Show resolved
Hide resolved
spring-web/src/main/java/org/springframework/http/MediaType.java
Outdated
Show resolved
Hide resolved
Parsing media types is a known hot spot and we need to be careful in how it's implemented for efficiency. The proposed solution produces more garbage than it needs to by creating a Couldn't we simply always loop over each character from the input string along with a boolean for whether we're inside quotes? For every "," that's not inside quotes, take a substring and it to the List. |
…double quoted" This reverts commit 61f664b
@rstoyanchev thanks for the review. Totally understand. Submitting now an update to this PR that is focused primarily on performance. |
…uoted Refactoring focusing on performance
Thank you for working on the issue. Essentially it means that just toggling on quotes is not enough. Maybe add another boolean for escapeMode:
|
@dimitrisli this looks much better. I just noticed we have a similar top level method in MimeTypeUtils. @Kuerten I can't find any evidence of the existing code supporting an escaped quote inside a quoted parameter. In fact I don't think it works like that now. Did you actually see that anywhere? In any case, it's worth adding such test cases while we are at it. |
…oted Applying the same logic on the MimeTypeUtils#parseMimeTypes() parsing from a string a tokenized list of mime types
@Kuerten thanks for the detailed description of the additional case. @rstoyanchev good spotting. I've amended accordingly also adding similar test cases. Regarding the additional case of escaped quote within a quoted param - sorry I might have got this wrong but it's not clear to me how this can be covered simply with additional tests without also a code change on the |
I think the idea is to add the test case and to make the change so the tests will pass. |
…ble quoted Supporting escaped doube quotes within double quotes
…ble quoted removing unecessary check of i > 0 since isQuoted cannot be true on first iteration (i==0). Consequently on first iteration this if-branch cannot be entered guarateeing i > 0. This way the i-1 check cannot be out of bound.
@rstoyanchev @Kuerten I've added support for escaped double quotes within double quotes - please review. Essentially instead of maintaining another boolean I'm checking for double quotes character while One detail: the |
…ble quoted trivial formatting change
Thanks for adding the cases. I think there is (at least) one more case you could look at: Assume I want to have a literal backslash as the parameter value. Since the backslash is not a |
…ble quoted Adding tests for escaped backslash
@Kuerten thanks for that. I've added tests to reflect this exact case and it seems to be passing without needing a change. The reason is that the backslash is considered only as a previous-character-check if the current character is a double quote. It would have been susceptible to this case if there was a boolean to toggle and keep track of the escaped backslash I believe. Please review |
I've processed this PR with some further modifications, notably creating a @dimitrisli thank you for taking the time to submit this contribution and move the ticket forward! |
Adding functionality to: