From 91939161aace35823f7a60b25647d5e23285c556 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 15 Jan 2018 15:00:58 +0000 Subject: [PATCH] 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.) --- app/helpers/blob_helper.rb | 2 ++ .../41666-cannot-search-with-keyword-merge-2.yml | 5 +++++ spec/helpers/blob_helper_spec.rb | 7 +++++++ 3 files changed, 14 insertions(+) create mode 100644 changelogs/unreleased/41666-cannot-search-with-keyword-merge-2.yml 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 %(
#{highlighted}
) 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(%[
:type "assem"))
]) 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(%[
(make-pathname :defaults name\n:type "assem"))
]) + end + it 'highlights single block' do expected = %Q[
(make-pathname :defaults name
 :type "assem"))
] -- GitLab