fnando / browser

Do some browser detection with Ruby. Includes ActionController integration.
MIT License
2.45k stars 361 forks source link

Updating to version 4.0+ causes a stack level too deep error #459

Closed diasks2 closed 2 years ago

diasks2 commented 4 years ago

Description

Upgrading from 3.03 to 4.0+ causes a stack level too deep error.

How to reproduce

require "browser/aliases"

class MyController < ApplicationController
  Browser::Base.include(Browser::Aliases)
  def show
    @browser = get_browser_details
   end

  private
  def get_browser_details
    return {
      known: browser.known?,
      full_version: browser.full_version,
      meta: browser.meta,
      name: browser.name,
      device: browser.device,
      device_id: browser.device.id,
      device_name: browser.device.name,
      platform: browser.platform,
      platform_id: browser.platform.id,
      platform_name: browser.platform.name,
      platform_version: browser.platform.version
    }
  end
end

What do you expect

No issues in updating to 4.0+ with the above code.

What happened instead

SystemStackError (stack level too deep)

Software:

fnando commented 4 years ago

Hi there! Can you create an app that reproduces this issue? I tried spinning up this app but it didn't raise any errors. Save it as config.ru then run rackup to start the app.

# frozen_string_literal: true

require "bundler/inline"

gemfile do
  gem "rails", "5.2.4.2"
  gem "browser"
end

require "rails"
require "action_controller/railtie"
require "action_view/railtie"

require "browser"
require "browser/aliases"

class HomeController < ActionController::Base
  Browser::Base.include(Browser::Aliases)

  def index
    render json: JSON.dump(
      known: browser.known?,
      full_version: browser.full_version,
      meta: browser.meta,
      name: browser.name,
      device: browser.device,
      device_id: browser.device.id,
      device_name: browser.device.name,
      platform: browser.platform,
      platform_id: browser.platform.id,
      platform_name: browser.platform.name,
      platform_version: browser.platform.version
    )
  end
end

class App < Rails::Application
  routes.append do
    get "/" => "home#index"
  end

  initialize!
end

run App