Commit 91939161 authored by Sean McGivern's avatar Sean McGivern

Only highlight search results under the highlighting size limit

We should use this limit everywhere, but especially in project search results,
where we could be highlighting very long single lines. (Typical examples:
minified JavaScript, and JSON data files.)
parent 82f4564f
module BlobHelper module BlobHelper
def highlight(blob_name, blob_content, repository: nil, plain: false) def highlight(blob_name, blob_content, repository: nil, plain: false)
plain ||= blob_content.length > Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE
highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository) highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository)
raw %(<pre class="code highlight"><code>#{highlighted}</code></pre>) raw %(<pre class="code highlight"><code>#{highlighted}</code></pre>)
end end
......
---
title: Only highlight search results under the highlighting size limit
merge_request: 16462
author:
type: performance
...@@ -22,6 +22,13 @@ describe BlobHelper do ...@@ -22,6 +22,13 @@ describe BlobHelper do
expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line" lang="">:type "assem"))</span></code></pre>]) expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line" lang="">:type "assem"))</span></code></pre>])
end end
it 'returns plaintext for long blobs' do
stub_const('Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE', 1)
result = helper.highlight(blob_name, blob_content)
expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem"))</span></code></pre>])
end
it 'highlights single block' do it 'highlights single block' do
expected = %Q[<pre class="code highlight"><code><span id="LC1" class="line" lang="common_lisp"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span> expected = %Q[<pre class="code highlight"><code><span id="LC1" class="line" lang="common_lisp"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>
<span id="LC2" class="line" lang="common_lisp"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span></code></pre>] <span id="LC2" class="line" lang="common_lisp"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span></code></pre>]
......
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