Skip to content

Commit 88accfd

Browse files
Increased limit to 100k lines, warning message is now on bottom and linked to raw
1 parent 2cebd53 commit 88accfd

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

custom/conf/app.example.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ LEVEL = Info
13361336
;MAX_FILE_SIZE = 524288
13371337
;;
13381338
;; Maximum allowed rows to render CSV files. (Set to 0 for no limit)
1339-
;MAX_ROWS = 5000
1339+
;MAX_ROWS = 100000
13401340

13411341
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13421342
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

modules/markup/csv/csv.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
3939
{Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)},
4040
{Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
4141
{Element: "td", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
42-
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(`tw-flex tw-justify-center tw-items-center`)},
43-
{Element: "a", AllowAttr: "href", Regexp: regexp.MustCompile(`\?display=source`)},
42+
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(`tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14`)},
43+
{Element: "a", AllowAttr: "href", Regexp: regexp.MustCompile(``)},
4444
}
4545
}
4646

@@ -81,7 +81,6 @@ func writeField(w io.Writer, element, class, field string) error {
8181
// Render implements markup.Renderer
8282
func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
8383
tmpBlock := bufio.NewWriter(output)
84-
warnBlock := bufio.NewWriter(tmpBlock)
8584
maxSize := setting.UI.CSV.MaxFileSize
8685
maxRows := setting.UI.CSV.MaxRows
8786

@@ -129,23 +128,22 @@ func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.W
129128
row++
130129
}
131130

131+
if _, err = tmpBlock.WriteString("</table>"); err != nil {
132+
return err
133+
}
134+
132135
// Check if maxRows or maxSize is reached, and if true, warn.
133136
if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) {
134137
locale := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
135138

136139
// Construct the HTML string
137-
warn := `<div class="tw-flex tw-justify-center tw-items-center"><div>` + locale.TrString("repo.file_too_large") + ` <a class="source" href="?display=source">` + locale.TrString("repo.file_view_source") + `</a></div></div>`
140+
warn := `<div class="tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14"><div>` + locale.TrString("repo.file_too_large") + ` <a class="source" href="` + ctx.Links.RawLink() + `/` + ctx.RelativePath + `">` + locale.TrString("repo.file_view_raw") + `</a></div></div>`
138141

139142
// Write the HTML string to the output
140-
if _, err := warnBlock.WriteString(warn); err != nil {
141-
return err
142-
}
143-
if err = warnBlock.Flush(); err != nil {
143+
if _, err := tmpBlock.WriteString(warn); err != nil {
144144
return err
145145
}
146146
}
147-
if _, err = tmpBlock.WriteString("</table>"); err != nil {
148-
return err
149-
}
147+
150148
return tmpBlock.Flush()
151149
}

modules/setting/ui.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var UI = struct {
111111
MaxRows int
112112
}{
113113
MaxFileSize: 524288,
114-
MaxRows: 5000,
114+
MaxRows: 100000,
115115
},
116116
Admin: struct {
117117
UserPagingNum int

0 commit comments

Comments
 (0)