<commit_before># -*- coding: utf-8 -*-

module SortablesHelper
  def sort_query(valid_fields, query_object, replacements = {}, defaults = {dir: :asc})
    valid_fields = valid_fields.map { |elem| elem.to_sym }
    controller_nam = controller_path.gsub(/\//, '-')

    cookie_key_scol = ("cforum_" + controller_nam + "-sort_column").to_sym
    cookie_key_sord = ("cforum_" + controller_nam + "-sort_direction").to_sym
    have_to_set_cookie = false

    if params[:sort].blank?
      @_sort_column = cookies[cookie_key_scol] || valid_fields.first
    else
      @_sort_column = params[:sort]
      have_to_set_cookie = true
    end

    if params[:dir].blank?
      @_sort_direction = cookies[cookie_key_sord] || defaults[:dir]
    else
      @_sort_direction = params[:dir]
      have_to_set_cookie = true
    end

    @_sort_direction = :asc unless [:asc, :desc].include?(@_sort_direction.to_sym)
    @_sort_direction = @_sort_direction.to_sym
    @_sort_column = valid_fields.first unless valid_fields.include?(@_sort_column.to_sym)
    @_sort_column = @_sort_column.to_sym

    if have_to_set_cookie
      cookies[cookie_key_scol] = {value: @_sort_column, expires: 1.year.from_now}
      cookies[cookie_key_sord] = {value: @_sort_direction, expires: 1.year.from_now}
    end

    order_name = if replacements and replacements[@_sort_column]
                   replacements[@_sort_column]
                 else
                   @_sort_column
                 end

    return query_object.order("(#{order_name}) #{@_sort_direction}")
  end

  def sortable(colname, col, method)
    if method.is_a?(Proc)
      link_asc = method.call(col, 'asc')
      link_desc = method.call(col, 'desc')
    else
      link_asc = self.send(method, sort: col, dir: 'asc')
      link_desc = self.send(method, sort: col, dir: 'desc')<commit_msg>fix: escape order column name<commit_after># -*- coding: utf-8 -*-

module SortablesHelper
  def sort_query(valid_fields, query_object, replacements = {}, defaults = {dir: :asc})
    valid_fields = valid_fields.map { |elem| elem.to_sym }
    controller_nam = controller_path.gsub(/\//, '-')

    cookie_key_scol = ("cforum_" + controller_nam + "-sort_column").to_sym
    cookie_key_sord = ("cforum_" + controller_nam + "-sort_direction").to_sym
    have_to_set_cookie = false

    if params[:sort].blank?
      @_sort_column = cookies[cookie_key_scol] || valid_fields.first
    else
      @_sort_column = params[:sort]
      have_to_set_cookie = true
    end

    if params[:dir].blank?
      @_sort_direction = cookies[cookie_key_sord] || defaults[:dir]
    else
      @_sort_direction = params[:dir]
      have_to_set_cookie = true
    end

    @_sort_direction = :asc unless [:asc, :desc].include?(@_sort_direction.to_sym)
    @_sort_direction = @_sort_direction.to_sym
    @_sort_column = valid_fields.first unless valid_fields.include?(@_sort_column.to_sym)
    @_sort_column = @_sort_column.to_sym

    if have_to_set_cookie
      cookies[cookie_key_scol] = {value: @_sort_column, expires: 1.year.from_now}
      cookies[cookie_key_sord] = {value: @_sort_direction, expires: 1.year.from_now}
    end

    order_name = if replacements and replacements[@_sort_column]
                   replacements[@_sort_column]
                 else
                   @_sort_column
                 end

    return query_object.order("(\"#{order_name}\") #{@_sort_direction}")
  end

  def sortable(colname, col, method)
    if method.is_a?(Proc)
      link_asc = method.call(col, 'asc')
      link_desc = method.call(col, 'desc')
    else
      link_asc = self.send(method, sort: col, dir: 'asc')
      link_desc = self.send(method, sort: col, dir: 'desc')
{'fraction_non_alphanumeric': 0.12207721587819467, 'fraction_numerical': 0.0016313213703099511, 'mean_word_length': 3.253179190751445, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054825', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1224, 'n_words': 231}