Commit 4e180a7c authored by Nick Thomas's avatar Nick Thomas

Introduce a rendering limit for commit titles

We pass "full" commit titles through Banzai in just one place:
Projects::RefsController#logs_tree (via Gitlab::TreeSummary). It is
shown (truncated to 100 characters, with the rest in tooltips) on the
repository file browser.

Permitting unlimited-length lines to be passed through banzai is a
recipe for puma timeouts, so add a 1KiB limit to these, mirroring the
1MiB limit we added to commit descriptions.

We also clean up the omission string used (from unicode to '...') so it
renders correctly in more places.
parent 64b4cca9
......@@ -36,7 +36,7 @@ class Commit
LINK_EXTENSION_PATTERN = /(patch)/.freeze
cache_markdown_field :title, pipeline: :single_line
cache_markdown_field :full_title, pipeline: :single_line
cache_markdown_field :full_title, pipeline: :single_line, limit: 1.kilobyte
cache_markdown_field :description, pipeline: :commit_description, limit: 1.megabyte
class << self
......
---
title: Introduce a rendering limit for commit titles
merge_request: 52904
author:
type: performance
......@@ -127,6 +127,15 @@ It's possible that this limit will be changed to a lower number in the future.
- **Max size:** ~1 million characters / ~1 MB
## Size of commit titles and descriptions
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/292039) in GitLab 13.9
Commits with arbitrarily large messages may be pushed to GitLab, but when
displaying commits, titles (the first line of the commit message) will be
limited to 1KiB, and descriptions (the rest of the message) will be limited to
1MiB.
## Number of issues in the milestone overview
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/39453) in GitLab 12.10.
......
......@@ -6,7 +6,9 @@ module Banzai
def call
return text unless context.key?(:limit)
text.truncate_bytes(context[:limit])
# Use three dots instead of the ellipsis Unicode character because
# some clients show the raw Unicode value in the merge commit.
text.truncate_bytes(context[:limit], omission: '...')
end
end
end
......
......@@ -22,7 +22,7 @@ RSpec.describe Banzai::Filter::TruncateSourceFilter do
it 'truncates UTF-8 text by bytes, on a character boundary' do
utf8_text = '日本語の文字が大きい'
truncated = '日'
truncated = '日...'
expect(filter(utf8_text, limit: truncated.bytesize)).to eq(truncated)
expect(filter(utf8_text, limit: utf8_text.bytesize)).to eq(utf8_text)
......
......@@ -30,6 +30,6 @@ RSpec.describe Banzai::Pipeline::PreProcessPipeline do
result = described_class.call(text, limit: 12)
expect(result[:output]).to eq('foo foo f')
expect(result[:output]).to eq('foo foo f...')
end
end
......@@ -400,6 +400,19 @@ eos
allow(commit).to receive(:safe_message).and_return(message + "\n" + message)
expect(commit.full_title).to eq(message)
end
it 'truncates html representation if more than 1KiB' do
# Commit title is over 2KiB on a single line
huge_commit_title = ('panic ' * 350) + 'trailing text'
allow(commit).to receive(:safe_message).and_return(huge_commit_title)
commit.refresh_markdown_cache
full_title_html = commit.full_title_html
expect(full_title_html.bytesize).to be < 2.kilobytes
expect(full_title_html).not_to include('trailing text')
end
end
describe 'description' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment