<commit_before>class PagesController < ApplicationController
  CheckitResult = Struct.new(:status, :valid_cert, :is_redirect, :is_error, :redirect_perm, :redirect_dest)
  ERROR_MESSAGE = "Please enter a URL or domain name"

  before_action :authenticate_user!, only: [
    :inside
  ]


  def home
    redirect_to projects_path if current_user
  end


  def checkit
  	# Clean up the input and make safe
  	@user_input = params[:url_or_domain_name].strip
    unless /\A[[:alnum:]\-.]{4,63}\z/ === @user_input  # Just a safety check:
      flash[:alert] = ERROR_MESSAGE                    # valid characters & length
    	redirect_to root_path
      return
    end

    test_results = check(@user_input)
    if test_results.is_redirect
      @redirect_kind = test_results.redirect_perm ? 'permanent' : 'temporary'
      @redirect_dest = test_results.redirect_dest
      @valid_cert    = test_results.valid_cert
      render 'checkit_with_redirect'
    elsif test_results.is_error
      render 'checkit_with_error'
    else
      @http_status = test_results.status
      @valid_cert  = test_results.valid_cert
      render 'checkit_no_redirect'
    end
  end
  
<commit_msg>further input validation<commit_after>class PagesController < ApplicationController
  CheckitResult = Struct.new(:status, :valid_cert, :is_redirect, :is_error, :redirect_perm, :redirect_dest)
  ERROR_MESSAGE = "Please enter a URL or domain name"

  before_action :authenticate_user!, only: [
    :inside
  ]


  def home
    redirect_to projects_path if current_user
  end


  def checkit
  	# Clean up the input and do a little checking
  	@user_input = params[:url_or_domain_name].strip
    unless /\A[^|<>"\\`^{}[:space:]]{4,63}\z/ === @user_input
      flash[:alert] = ERROR_MESSAGE
    	redirect_to root_path
      return
    end

    test_results = check(@user_input)
    if test_results.is_redirect
      @redirect_kind = test_results.redirect_perm ? 'permanent' : 'temporary'
      @redirect_dest = test_results.redirect_dest
      @valid_cert    = test_results.valid_cert
      render 'checkit_with_redirect'
    elsif test_results.is_error
      render 'checkit_with_error'
    else
      @http_status = test_results.status
      @valid_cert  = test_results.valid_cert
      render 'checkit_no_redirect'
    end
  end
  

{'fraction_non_alphanumeric': 0.08597481545809814, 'fraction_numerical': 0.0026052974381241857, 'mean_word_length': 3.3969465648854964, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '5306184', 'n_tokens_mistral': 748, 'n_tokens_neox': 718, 'n_words': 163}