ruby-changes:50595
From: k0kubun <ko1@a...>
Date: Tue, 13 Mar 2018 21:56:10 +0900 (JST)
Subject: [ruby-changes:50595] k0kubun:r62743 (trunk): Fix FrozenError on `Ripper.slice`
k0kubun 2018-03-13 21:56:04 +0900 (Tue, 13 Mar 2018) New Revision: 62743 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62743 Log: Fix FrozenError on `Ripper.slice` Currently `Ripper.slice` raises a FrozenError ```ruby require 'ripper' p Ripper.slice('foo', 'ident') ``` ``` /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:193:in `concat': can't modify frozen String (FrozenError) from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:193:in `block in compile' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:190:in `scan' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:190:in `compile' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:169:in `initialize' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:151:in `new' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:151:in `token_match' from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:144:in `slice' from /tmp/tmp.kb4cnhvum2/test.rb:2:in `<main>' ``` This patch will fix the problem. [Fix GH-1837] From: Masataka Pocke Kuwabara <kuwabara@p...> Modified files: trunk/ext/ripper/lib/ripper/lexer.rb Index: ext/ripper/lib/ripper/lexer.rb =================================================================== --- ext/ripper/lib/ripper/lexer.rb (revision 62742) +++ ext/ripper/lib/ripper/lexer.rb (revision 62743) @@ -186,7 +186,7 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L186 if m = /[^\w\s$()\[\]{}?*+\.]/.match(pattern) raise CompileError, "invalid char in pattern: #{m[0].inspect}" end - buf = '' + buf = +'' pattern.scan(/(?:\w+|\$\(|[()\[\]\{\}?*+\.]+)/) do |tok| case tok when /\w/ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/