pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

Rails crashes with 'trace trap' error #18

Closed natew closed 11 years ago

natew commented 12 years ago

When attempting to run Pygments without the lexer set, I get a trace trap crash with Rails.

zsh: trace trap  rails s

Any of the following will cause the crash:

Pygments.highlight(code)
Pygments.lexer_name_for(code)

This will not crash and works properly:

Pygments.highlight(code, :lexer => 'javascript')

Using this input:

function makeExpandingArea(container) {
  var area = container.querySelector('textarea'),
      span = container.querySelector('span');

 if (area.addEventListener) {
   area.addEventListener('input', function() {
     span.textContent = area.value;
   }, false);
   span.textContent = area.value;
 } else if (area.attachEvent) {
   // IE8 compatibility
   area.attachEvent('onpropertychange', function() {
     span.innerText = area.value;
   });
   span.innerText = area.value;
 }

Running Lion on Mac with Ruby 1.9.2, Rails 3.2.0. Here's my gemfile.lock:

  remote: git://github.com/rsl/stringex.git
  revision: cdac489cb78de158dd52cfbfa388a3c9c3069e4e
  specs:
    stringex (1.3.2)

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.0)
      actionpack (= 3.2.0)
      mail (~> 2.4.0)
    actionpack (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.0)
      rack (~> 1.4.0)
      rack-cache (~> 1.1)
      rack-test (~> 0.6.1)
      sprockets (~> 2.1.2)
    activemodel (3.2.0)
      activesupport (= 3.2.0)
      builder (~> 3.0.0)
    activerecord (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
      arel (~> 3.0.0)
      tzinfo (~> 0.3.29)
    activeresource (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
    activesupport (3.2.0)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    addressable (2.2.7)
    arel (3.0.2)
    aws-sdk (1.3.9)
      httparty (~> 0.7)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
      uuidtools (~> 2.1)
    bcrypt-ruby (3.0.1)
    bcrypt-ruby (3.0.1-x86-mingw32)
    blankslate (2.1.2.4)
    builder (3.0.0)
    capistrano (2.9.0)
      highline
      net-scp (>= 1.0.0)
      net-sftp (>= 2.0.0)
      net-ssh (>= 2.0.14)
      net-ssh-gateway (>= 1.1.0)
    cocaine (0.2.1)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.2.0)
    erubis (2.7.0)
    execjs (1.3.0)
      multi_json (~> 1.0)
    faraday (0.7.6)
      addressable (~> 2.2)
      multipart-post (~> 1.1)
      rack (~> 1.1)
    ffi (1.0.11)
    highline (1.6.11)
    hike (1.2.1)
    httparty (0.8.1)
      multi_json
      multi_xml
    i18n (0.6.0)
    journey (1.0.3)
    jquery-rails (2.0.1)
      railties (>= 3.2.0, < 5.0)
      thor (~> 0.14)
    json (1.6.5)
    kaminari (0.13.0)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
      railties (>= 3.0.0)
    linguist (0.4.0)
      rails (>= 3.0.0, < 4.0.0)
      redis (~> 2.2.0)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.18)
    multi_json (1.1.0)
    multi_xml (0.4.2)
    multipart-post (1.1.5)
    net-scp (1.0.4)
      net-ssh (>= 1.99.1)
    net-sftp (2.0.5)
      net-ssh (>= 2.0.9)
    net-ssh (2.3.0)
    net-ssh-gateway (1.1.0)
      net-ssh (>= 1.99.1)
    nokogiri (1.5.2)
    nokogiri (1.5.2-x86-mingw32)
    oauth (0.4.5)
    oauth2 (0.5.2)
      faraday (~> 0.7)
      multi_json (~> 1.0)
    paperclip (3.0.1)
      activemodel (>= 3.0.0)
      activerecord (>= 3.0.0)
      activesupport (>= 3.0.0)
      cocaine (>= 0.0.2)
      mime-types
    pg (0.13.2)
    pg (0.13.2-x86-mingw32)
    polyglot (0.3.3)
    pygments.rb (0.2.8)
      rubypython (~> 0.5.3)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.2.0)
      actionmailer (= 3.2.0)
      actionpack (= 3.2.0)
      activerecord (= 3.2.0)
      activeresource (= 3.2.0)
      activesupport (= 3.2.0)
      bundler (~> 1.0)
      railties (= 3.2.0)
    railties (3.2.0)
      actionpack (= 3.2.0)
      activesupport (= 3.2.0)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (~> 0.14.6)
    rake (0.9.2.2)
    rdoc (3.12)
      json (~> 1.4)
    redcarpet (2.1.1)
    redis (2.2.2)
    rubypython (0.5.3)
      blankslate (>= 2.1.2.3)
      ffi (~> 1.0.7)
    sass (3.1.15)
    sass-rails (3.2.5)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    slim (1.2.0)
      temple (~> 0.4.0)
      tilt (~> 1.3.3)
    sorcery (0.7.7)
      bcrypt-ruby (~> 3.0.0)
      oauth (~> 0.4.4)
      oauth2 (~> 0.5.1)
      sorcery
    sprockets (2.1.2)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.5)
    sqlite3 (1.3.5-x86-mingw32)
    temple (0.4.0)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.32)
    uglifier (1.2.3)
      execjs (>= 0.3.0)
      multi_json (>= 1.0.2)
    uuidtools (2.1.2)

PLATFORMS
  ruby
  x86-mingw32

DEPENDENCIES
  aws-sdk (~> 1.3.4)
  bcrypt-ruby (~> 3)
  capistrano
  coffee-rails (~> 3)
  jquery-rails (~> 2)
  kaminari (~> 0.13)
  linguist
  paperclip (~> 3.0)
  pg (~> 0.13)
  pygments.rb
  rails (~> 3)
  redcarpet
  sass-rails (~> 3)
  slim
  sorcery
  sqlite3 (~> 1)
  stringex (~> 1)!
  uglifier (~> 1)
natew commented 12 years ago

No one gets this? Can't get it to work on my dev or deploy machines (ubuntu and mac).

And actually the ruby version is 1.9.3-p0 I believe, not sure if thats why.

jgaskins commented 12 years ago

I get this, too, on OS X Lion with Ruby 1.9.3-p125.

I'm porting my blog over to use pygments.rb from Albino. It renders the Ruby example inside it perfectly, but it consistently crashes while attempting to work with the Gherkin example I have.

Here's the code:

class PygmentsHTML < Redcarpet::Render::HTML
   def block_code(code, language)
     Pygments.highlight(code, lexer: language)
   end
end

I verified that the code and language arguments are passed in properly and Pygments is working fine in irb, but it's having trouble from within Rails.

dpogorzelski commented 12 years ago

Same problem here

h6y3 commented 12 years ago

I see this issue, also on a Lion/Mac system (but not Ubuntu). To reproduce, on 1.9.3p125: simply get the gollum gem and run it against your github wiki which has a page that performs syntax highlighting. It will blow up after that - so any Mac user using gollum (which is great for editing github pages) is going to run into this if they do syntax highlighting.

h6y3 commented 12 years ago

Also check out this related link which I think could be explaining the cause for Mac crashes: https://github.com/gitlabhq/gitlabhq/pull/245

jamesduncombe commented 12 years ago

Getting the same problem here on OSX 10.6.8, ruby-1.9.3-p125, pygments.rb v0.2.13.

It seems to work fine on my other Mac which is running OSX Lion.

tnm commented 11 years ago

This is fixed since 0.3.0.