Skip to content

Allow search of code with hyphen

#3348 (closed)

Sorry to disturb

I find there will be 500 error if search key is begin with dash/hyphen. ( Search "--abc" or "- abc")

I read app/models/repository.rb

  def search_files(query, ref)
    offset = 2
    args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref})
    Gitlab::Popen.popen(args, path_to_repo).first.scrub.split(/^--$/)
  end

The #{query} can't begin with dash/hyphen.

And I learn from google that, if we put "--" before #{query}, it signify the end of the options, and fix our 500 error.

http://stackoverflow.com/questions/2427913/how-can-i-grep-for-a-string-that-begins-with-a-dash-hyphen

http://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash/11382#11382


Can we fix the 500 error in this way? Or maybe you will fix it in some better way.

Thank you : )

Merge request reports