diff options
author | Sean McGivern <sean@gitlab.com> | 2018-01-15 15:00:58 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-01-16 11:56:07 +0000 |
commit | 91939161aace35823f7a60b25647d5e23285c556 (patch) | |
tree | e74ab86561ca6f96fc57110712bd967317e7e53b | |
parent | 82f4564fb7dc57a9a7bb6a052926ee219bb29b13 (diff) | |
download | gitlab-ce-91939161aace35823f7a60b25647d5e23285c556.tar.gz |
Only highlight search results under the highlighting size limit41666-cannot-search-with-keyword-merge
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.)
-rw-r--r-- | app/helpers/blob_helper.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/41666-cannot-search-with-keyword-merge-2.yml | 5 | ||||
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 7 |
3 files changed, 14 insertions, 0 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 5e3b2e5581c..a6e1de6ffdc 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,6 +1,8 @@ module BlobHelper 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) + raw %(<pre class="code highlight"><code>#{highlighted}</code></pre>) end diff --git a/changelogs/unreleased/41666-cannot-search-with-keyword-merge-2.yml b/changelogs/unreleased/41666-cannot-search-with-keyword-merge-2.yml new file mode 100644 index 00000000000..48893862071 --- /dev/null +++ b/changelogs/unreleased/41666-cannot-search-with-keyword-merge-2.yml @@ -0,0 +1,5 @@ +--- +title: Only highlight search results under the highlighting size limit +merge_request: 16462 +author: +type: performance diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 04620f6d88c..a030796c54e 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -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>]) 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 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>] |