diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-06-20 15:59:58 +0300 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-06-20 19:05:12 +0300 |
commit | 6905a62867067f2f61feb6734be3972cb5b9f7a7 (patch) | |
tree | ea953acc268cc1c747870ee88d2892a174b65878 /lib/gitlab/search | |
parent | f4605ad880e9b76c94218cb7c4f16215c4f62e8e (diff) |
Build correct basenames for title search results
The "basename" here needs to be the full path without the trailing
extension, instead of stripping the leading path as well.
This was previously fixed in 2f36efa0871 inside the view, but the
problematic code was still present in FoundBlob, and the corresponding
spec didn't actually use a child wiki page to properly verify the fix.
Diffstat (limited to 'lib/gitlab/search')
-rw-r--r-- | lib/gitlab/search/found_blob.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/gitlab/search/found_blob.rb b/lib/gitlab/search/found_blob.rb index a62ab1521a7..01ce90c85f7 100644 --- a/lib/gitlab/search/found_blob.rb +++ b/lib/gitlab/search/found_blob.rb @@ -93,7 +93,7 @@ module Gitlab data = { id: blob.id, binary_filename: blob.path, - binary_basename: File.basename(blob.path, File.extname(blob.path)), + binary_basename: path_without_extension(blob.path), ref: ref, startline: 1, binary_data: blob.data, @@ -111,6 +111,10 @@ module Gitlab content_match.match(FILENAME_REGEXP) { |matches| matches[:filename] } end + def path_without_extension(path) + Pathname.new(path).sub_ext('').to_s + end + def parsed_content strong_memoize(:parsed_content) do if content_match @@ -137,8 +141,7 @@ module Gitlab filename = matches[:filename] startline = matches[:startline] startline = startline.to_i - index - extname = Regexp.escape(File.extname(filename)) - basename = filename.sub(/#{extname}$/, '') + basename = path_without_extension(filename) end data << line.sub(prefix.to_s, '') |