<commit_before>require 'uri'

class OembedController < ApplicationController
  respond_to :html
  
  def show

    u = URI.parse(params[:url])
    slug = u.path.gsub /\//, '' 
    proposal = Proposal.find_by_slug slug

    if !proposal
      render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
      return
    end

    authorize! "read proposal", proposal

    width = params[:maxwidth].to_i
<commit_msg>fix bug with oembed of subdomain with underscore in name<commit_after>require 'uri'

class OembedController < ApplicationController
  respond_to :html
  
  def show

    url = params[:url]
    begin
      u = URI.parse(url)
    rescue URI::InvalidURIError  # happens when subdomain contains an underscore
      host = url.match(".+\:\/\/([^\/]+)")[1]
      u = URI.parse(url.sub(host, 'dummy-host'))
      u.instance_variable_set('@host', host)
    end

    slug = u.path.gsub /\//, '' 
    proposal = Proposal.find_by_slug slug

    if !proposal
      render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
      return
    end

    authorize! "read proposal", proposal

    width = params[:maxwidth].to_i

{'fraction_non_alphanumeric': 0.1352493660185968, 'fraction_numerical': 0.005917159763313609, 'mean_word_length': 2.9205298013245033, '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': '918543', 'n_tokens_mistral': 397, 'n_tokens_neox': 382, 'n_words': 94}