Skip to content
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 "array index out of bounds" problem reported by LGTM.com #23485

Closed
wants to merge 2 commits into from
Closed

Fix "array index out of bounds" problem reported by LGTM.com #23485

wants to merge 2 commits into from

Conversation

jbduncan
Copy link
Contributor

@pivotal-issuemaster
Copy link

@jbduncan Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@jbduncan Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 19, 2019
@rstoyanchev rstoyanchev self-assigned this Aug 20, 2019
@rstoyanchev rstoyanchev added this to the 5.2 RC2 milestone Aug 20, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 20, 2019
@rstoyanchev
Copy link
Contributor

Could you re-work the tests to avoid the use reflection?

@mentallurg
Copy link

@rstoyanchev: The only reason for reflection is to test private method. Then one should implement a test for public methods. I find it better. But the tests already contained 2 tests for exactly this same private method and they of course use reflection. Be consistent. Either accept new reflection based tests or rework other already existing reflection based tests.

Copy link

@mentallurg mentallurg left a comment

Choose a reason for hiding this comment

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

I find the reflection based tests OK in this case. If one prefers not to use reflection in the tests, then it should be handled in a separate issue, and that would be a huge change, because there are already many reflection based tests in Spring.

@jbduncan
Copy link
Contributor Author

jbduncan commented Sep 1, 2019

Hi @rstoyanchev @mentallurg, sorry for the delay in responding! I was on holiday and then catching up with work and IRL things.

I wasn't sure about introducing a reflection-based test either, but I used the same reasoning that @mentallurg did and I decided to use reflection for consistency with the other tests.

@rstoyanchev Would you prefer that I switch all the reflection-based tests in ContentDispositionTests to use the public API instead?

I'm not sure if either of you are Spring maintainers, but is there anything else you'd like me to do before this PR is merged in? :)

@sbrannen
Copy link
Member

sbrannen commented Sep 2, 2019

I'm not sure if either of you are Spring maintainers

@jbduncan, you can look at comments from people to see if there is a Member button, like the one you see for Rossen here: #23485 (comment)

The People page can also be of assistance for the entire Spring portfolio: https://github.com/orgs/spring-projects/people

@sbrannen
Copy link
Member

sbrannen commented Sep 2, 2019

I wasn't sure about introducing a reflection-based test either, but I used the same reasoning that @mentallurg did and I decided to use reflection for consistency with the other tests.

That's valid reasoning.

However, I don't see any reason that encodeHeaderFieldParam() and decodeHeaderFieldParam() should be private. Changing their visibility to package-private would remove the need for reflection in the tests since ContentDispositionTests resides in the same package as ContentDisposition, and making that change shouldn't hurt anything with regard to encapsulation.

@rstoyanchev, WDYT?

@jbduncan
Copy link
Contributor Author

jbduncan commented Sep 2, 2019

Hey @sbrannen, fancy meeting you here. :)

@jbduncan, you can look at comments from people to see if there is a Member button, like the one you see for Rossen here: #23485 (comment)

The People page can also be of assistance for the entire Spring portfolio: https://github.com/orgs/spring-projects/people

Oh cool, thank you for reminding me about that button and the existence of GitHub's "People" tab. Cheers! 👍

rstoyanchev added a commit that referenced this pull request Sep 3, 2019
Also minor refactoring in decoding in order to tolerate the absence of
a charset and treat as US_ASCII.

See gh-23485
rstoyanchev added a commit that referenced this pull request Sep 3, 2019
@rstoyanchev
Copy link
Contributor

This PR has been merged. I removed the use of reflection by doing actual parsing and/or formatting with an encoded filename attribute. There were even some existing tests like that so I don't know why we had reflection there in the first place.

The refactoring helped to uncover a small issue with tolerating "filename*" without a charset (i.e. US_ASCII) which the decode method was dealing with but the duplicate code in parse wasn't.

@jbduncan
Copy link
Contributor Author

jbduncan commented Sep 3, 2019

Thanks @rstoyanchev! 👍

@jbduncan jbduncan deleted the lgtm.com-fixes branch September 3, 2019 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants