<commit_before>class Projects::BranchesController < Projects::ApplicationController
  # Authorize
  before_filter :require_non_empty_project

  before_filter :authorize_download_code!
  before_filter :authorize_push_code!, only: [:create, :destroy]

  def index
    @sort = params[:sort] || 'name'
    @branches = @repository.branches_sorted_by(@sort)
    @branches = Kaminari.paginate_array(@branches).page(params[:page]).per(30)
  end

  def recent
    @branches = @repository.recent_branches
  end

  def create
    result = CreateBranchService.new(project, current_user).
        execute(params[:branch_name], params[:ref])

    if result[:status] == :success
      @branch = result[:branch]
      redirect_to project_tree_path(@project, @branch.name)
    else
      @error = result[:message]
      render action: 'new'
    end
  end

  def destroy
    DeleteBranchService.new(project, current_user).execute(params[:id])
    @branch_name = params[:id]

    respond_to do |format|
      format.html { redirect_to project_branches_path(@project) }
      format.js<commit_msg>Sanitize branch name and ref name<commit_after>class Projects::BranchesController < Projects::ApplicationController
  include ActionView::Helpers::SanitizeHelper
  # Authorize
  before_filter :require_non_empty_project

  before_filter :authorize_download_code!
  before_filter :authorize_push_code!, only: [:create, :destroy]

  def index
    @sort = params[:sort] || 'name'
    @branches = @repository.branches_sorted_by(@sort)
    @branches = Kaminari.paginate_array(@branches).page(params[:page]).per(30)
  end

  def recent
    @branches = @repository.recent_branches
  end

  def create
    branch_name = sanitize(strip_tags(params[:branch_name]))
    ref = sanitize(strip_tags(params[:ref]))
    result = CreateBranchService.new(project, current_user).
        execute(branch_name, ref)

    if result[:status] == :success
      @branch = result[:branch]
      redirect_to project_tree_path(@project, @branch.name)
    else
      @error = result[:message]
      render action: 'new'
    end
  end

  def destroy
    DeleteBranchService.new(project, current_user).execute(params[:id])
    @branch_name = params[:id]

    respond_to do |format|
      format.html { redirect_to project_branches_path(@project) }
      format.js
{'fraction_non_alphanumeric': 0.11005199306759099, 'fraction_numerical': 0.0017331022530329288, 'mean_word_length': 4.295871559633028, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2971894', 'n_tokens_mistral': 720, 'n_tokens_neox': 702, 'n_words': 138}