<commit_before>module Paloma
  module ActionControllerFilters
    
    def self.included base
      base.module_eval do
        prepend_view_path "#{Paloma.root}/app/views/"
        before_filter :js_callback
        after_filter :update_callback, :if => :html_response_from_render?
      end
    end

    
  protected
    
    def html_response_from_render?
      [nil, 'text/html'].include?(response.content_type) && self.status != 302 
    end

        
    def update_callback
      add_to_callbacks @__callback__, @__js_params__

      paloma_txt = view_context.render(
        :partial => "paloma/callback_hook",
        :locals => {:callbacks => session[:callbacks]})
      
      before_body_end_index = response_body[0].rindex('</body>')
      
      if before_body_end_index.present?
        before_body_end_content = response_body[0][0, before_body_end_index].html_safe
        after_body_end_content = response_body[0][before_body_end_index..-1].html_safe
        
        response_body[0] = before_body_end_content + paloma_txt + after_body_end_content
       
        response.body = response_body[0]
      else
        # If body tag is not present, append paloma_txt in the response body
        response.body = response_body[0] + paloma_txt<commit_msg>Bug Fix: Modifying value of response_body[0]<commit_after>module Paloma
  module ActionControllerFilters
    
    def self.included base
      base.module_eval do
        prepend_view_path "#{Paloma.root}/app/views/"
        before_filter :js_callback
        after_filter :update_callback, :if => :html_response_from_render?
      end
    end

    
  protected
    
    def html_response_from_render?
      [nil, 'text/html'].include?(response.content_type) && self.status != 302 
    end

        
    def update_callback
      add_to_callbacks @__callback__, @__js_params__

      paloma_txt = view_context.render(
        :partial => "paloma/callback_hook",
        :locals => {:callbacks => session[:callbacks]})
      
      before_body_end_index = response_body[0].rindex('</body>')
      
      if before_body_end_index.present?
        before_body_end_content = response_body[0][0, before_body_end_index].html_safe
        after_body_end_content = response_body[0][before_body_end_index..-1].html_safe
        
        response_body[0] = before_body_end_content + paloma_txt + after_body_end_content
       
        response.body = response_body[0]
      else
        # If body tag is not present, append paloma_txt in the response body
        response_body[0] += paloma_txt
        response.body = response_body[0]
{'fraction_non_alphanumeric': 0.08638642499035866, 'fraction_numerical': 0.009255688391824142, 'mean_word_length': 2.8774289985052315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3505521', 'n_tokens_mistral': 811, 'n_tokens_neox': 795, 'n_words': 145}