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

Replace regex usage for MIME parsing #17831

Merged
merged 2 commits into from Nov 27, 2021
Merged

Conversation

gabriel-vasile
Copy link
Contributor

@gabriel-vasile gabriel-vasile commented Nov 26, 2021

MIME types can have multiple optional parameters, eg:
video/webm; codecs="w/e codec"; charset="binary"
For these cases, regex will fail to drop all params from the MIME type.

This commit replaces the usage of regex for getting the "type/subtype" with mime.ParseMediaType.

MIME types can have multiple optional parameters, eg:
    video/webm; codecs="w/e codec"; charset="binary"
This commit replaces the usage of regex for getting the "type/subtype"
with mime.ParseMediaType.
@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2021

Codecov Report

Merging #17831 (e9eb764) into main (371ebce) will increase coverage by 0.00%.
The diff coverage is 45.45%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17831   +/-   ##
=======================================
  Coverage   45.54%   45.54%           
=======================================
  Files         808      808           
  Lines       90049    90056    +7     
=======================================
+ Hits        41009    41018    +9     
+ Misses      42487    42484    -3     
- Partials     6553     6554    +1     
Impacted Files Coverage Δ
modules/upload/upload.go 73.21% <25.00%> (-4.15%) ⬇️
routers/web/web.go 90.34% <57.14%> (-0.33%) ⬇️
modules/charset/charset.go 71.71% <0.00%> (-4.05%) ⬇️
modules/queue/queue_channel.go 95.00% <0.00%> (-1.67%) ⬇️
services/pull/pull.go 41.78% <0.00%> (ø)
routers/api/v1/repo/pull.go 29.35% <0.00%> (+0.51%) ⬆️
modules/queue/queue_bytefifo.go 59.88% <0.00%> (+0.59%) ⬆️
modules/queue/queue_disk_channel.go 62.72% <0.00%> (+1.77%) ⬆️
modules/queue/workerpool.go 50.00% <0.00%> (+2.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 789d251...e9eb764. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 26, 2021
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 26, 2021
@silverwind
Copy link
Member

Could you add a testcase or two here? Should be pretty simple.

@gabriel-vasile
Copy link
Contributor Author

I tried to think of a regression test for this change but I don't think there is any.
All MIME types returned by http.DetectContentType are processed correctly with the regex because they don't have multiple optional params nor they have any weird syntax like text/plain; param="weird;value".

Honestly, the only value this PR has is if sometime in the future http.DetectContentType is updated to return one of those weird MIME types for which the regex will fail.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 27, 2021
@wxiaoguang wxiaoguang merged commit 2e8fc5b into go-gitea:main Nov 27, 2021
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
MIME types can have multiple optional parameters, eg:
    video/webm; codecs="w/e codec"; charset="binary"
This commit replaces the usage of regex for getting the "type/subtype"
with mime.ParseMediaType.
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants