<commit_before>class RootController < ApplicationController

  before_filter :validate_template_param

  rescue_from ActionView::MissingTemplate, :with => :error_404

  caches_page :template, :raw_template

  def raw_template
    file_path = Rails.root.join("app", "views", "root", "#{params[:template]}.raw.html.erb")
    error_404 and return unless File.exists?(file_path)
    render :text => File.read(file_path)
  end

  def template
    render :action => params[:template]
  end

  private

  def validate_template_param
    unless params[:template] =~ /\A\w+\z/<commit_msg>Add comment explaining regex intent<commit_after>class RootController < ApplicationController

  before_filter :validate_template_param

  rescue_from ActionView::MissingTemplate, :with => :error_404

  caches_page :template, :raw_template

  def raw_template
    file_path = Rails.root.join("app", "views", "root", "#{params[:template]}.raw.html.erb")
    error_404 and return unless File.exists?(file_path)
    render :text => File.read(file_path)
  end

  def template
    render :action => params[:template]
  end

  private

  def validate_template_param
    # Allow alphanumeric and _ in template filenames.
    # Prevent any attempts to traverse directores etc...
    unless params[:template] =~ /\A\w+\z/
{'fraction_non_alphanumeric': 0.10844306738962045, 'fraction_numerical': 0.009295120061967466, 'mean_word_length': 4.451476793248945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5375843', 'n_tokens_mistral': 406, 'n_tokens_neox': 382, 'n_words': 96}