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 markdown meta parsing #12817

Merged
merged 6 commits into from
Sep 13, 2020
Merged

Conversation

jolheiser
Copy link
Member

Fixes #12815

This code should now exclude the separator lines themselves, so as long as there are two or more hyphens it will work as a separator and also YAML won't choke.

Included a minimal test case.

Signed-off-by: jolheiser <john.olheiser@gmail.com>
@jolheiser jolheiser added this to the 1.13.0 milestone Sep 11, 2020
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 11, 2020
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signed-off-by: jolheiser <john.olheiser@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2020

Codecov Report

Merging #12817 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12817      +/-   ##
==========================================
+ Coverage   43.13%   43.16%   +0.02%     
==========================================
  Files         654      654              
  Lines       72205    72205              
==========================================
+ Hits        31146    31165      +19     
+ Misses      36013    35990      -23     
- Partials     5046     5050       +4     
Impacted Files Coverage Δ
modules/markup/markdown/meta.go 90.90% <100.00%> (+90.90%) ⬆️
modules/process/manager.go 72.50% <0.00%> (-2.50%) ⬇️
modules/queue/unique_queue_disk_channel.go 53.84% <0.00%> (-1.54%) ⬇️
models/repo_list.go 78.57% <0.00%> (-0.90%) ⬇️
services/pull/pull.go 41.57% <0.00%> (-0.47%) ⬇️
modules/log/event.go 57.54% <0.00%> (+0.94%) ⬆️
models/unit.go 49.31% <0.00%> (+2.73%) ⬆️
modules/util/timer.go 85.71% <0.00%> (+42.85%) ⬆️

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 f91bb74...8e02820. Read the comment docs.

Signed-off-by: jolheiser <john.olheiser@gmail.com>
@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 Sep 12, 2020
@@ -25,20 +25,22 @@ func isYAMLSeparator(line string) bool {
// and returns the frontmatter metadata separated from the markdown content
func ExtractMetadata(contents string, out interface{}) (string, error) {
var front, body []string
var seps int
lines := strings.Split(contents, "\n")
for idx, line := range lines {
Copy link
Member

Choose a reason for hiding this comment

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

It's better to use Scanner.

scanner := bufio.NewScanner(strings.NewReader(contents))
var idx = 0 
for scanner.Scan() {
    line := scanner.Text()
    ...
    idx++
}

Copy link
Member Author

Choose a reason for hiding this comment

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

What's the advantage in this case?
We still need to scan the whole file so we can return body, and we've already checked file size prior to calling this func.

Copy link
Member

Choose a reason for hiding this comment

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

Less CPU and memory usage. But since it should be a small file, it's not necessary.

@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 Sep 12, 2020
@techknowlogick techknowlogick merged commit b2bda11 into go-gitea:master Sep 13, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
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. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue template format should be more forgiving
7 participants