mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-21 09:06:46 +09:00
perf(citation): optimize CITATION.cff rendering (#39575)
Rendering a CITATION.cff could use memory far out of proportion to the file, as every YAML alias copies its target into the formatted citation and the parser copies `%TAG` prefixes into every node. Files past these limits show no citation, like unparseable ones do today. - Skip files over 256 KiB, largest real-world file found is 80 KiB - Skip files with `%TAG` directives - Skip files whose aliases add more than 64 Ki nodes and value bytes - Skip self-referencing anchors, except a sequence listing itself Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
9bb8751b29
commit
2705abf7f3
4 files changed
+85
-19
No files matched your search
@@ -4,6 +4,7 @@
|
||||
package citation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -125,6 +126,10 @@ year = {in press}
|
||||
}`,
|
||||
},
|
||||
{cff: "title: No authors\nauthor:\n - name: Typo\n"},
|
||||
{cff: "title: T\nauthors: [{name: A}]\nmessage: " + strings.Repeat("x", MaxContentSize)},
|
||||
{cff: "title: T\nauthors: [{name: A}]\nmessage: &s " + strings.Repeat("x", maxAliasExpansion/2) + "\nlicense: [*s, *s]\n"},
|
||||
{cff: "%TAG !e! tag:example.com,2000:\n---\ntitle: T\nauthors: [{name: A}]\n"},
|
||||
{cff: "preferred-citation: &m {title: T, name: A, authors: [*m]}\n"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run("", func(t *testing.T) {
|
||||
@@ -135,3 +140,10 @@ year = {in press}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLikelyBibTeX(t *testing.T) {
|
||||
assert.True(t, IsLikelyBibTeX("@article{key, title={Title}}"))
|
||||
assert.True(t, IsLikelyBibTeX("Inproceedings\n{\n}\n"))
|
||||
assert.True(t, IsLikelyBibTeX("% comment\n\n@misc{key}\n% comment\n"))
|
||||
assert.False(t, IsLikelyBibTeX("not bib {}"))
|
||||
}
|
||||
Reference in new issue
Block a user