[ruby-dev:31781] `scan': character encodings differ (ArgumentError)

From: Kouhei Sutou <kou@...>
Date: 2007-09-15 01:23:51 UTC
List: ruby-dev #31781
須藤です。

trunkでは、encodingがUS-ASCIIな文字列をkcodeが"utf8"な正規表
現でscanしようとするとArgumentErrorが発生します。

  % /tmp/local/bin/ruby -v -e '"x".scan(/x/u)'
  ruby 1.9.0 (2007-09-14 patchlevel 0) [x86_64-linux]
  -e:1:in `scan': character encodings differ (ArgumentError)
          from -e:1:in `<main>'

これは一時的なものなのでしょうか?それとも、意図的な動作なの
でしょうか?


これが原因でREXMLは使い物にならなくなっています。

  % /tmp/local/bin/ruby -v -r rexml/document -e 'REXML::Document.new(%q(<a b="c"/>))'
  ruby 1.9.0 (2007-09-14 patchlevel 0) [x86_64-linux]
  /tmp/local/lib/ruby/1.9/rexml/element.rb:707: warning: shadowing outer local variable - child
  /tmp/local/lib/ruby/1.9/rexml/element.rb:757: warning: shadowing outer local variable - child
  /tmp/local/lib/ruby/1.9/rexml/doctype.rb:121: warning: shadowing outer local variable - child
  /tmp/local/lib/ruby/1.9/rexml/xpath_parser.rb:296: warning: shadowing outer local variable - node
  /tmp/local/lib/ruby/1.9/rexml/xpath_parser.rb:355: warning: shadowing outer local variable - node
  /tmp/local/lib/ruby/1.9/rexml/xpath_parser.rb:367: warning: shadowing outer local variable - node
  /tmp/local/lib/ruby/1.9/rexml/parsers/xpathparser.rb:335: warning: shadowing outer local variable - expr
  /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:90:in `raise': #<REXML::ParseException: #<ArgumentError: character encodings differ> (REXML::ParseException)
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:350:in `scan'
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:350:in `pull'
  /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:21:in `parse'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:233:in `build'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:42:in `initialize'
  -e:1:in `new'
  -e:1:in `<main>'
  ...
  Exception parsing
  Line: 
  Position: 
  Last 80 unconsumed characters:
  >
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:378:in `raise'
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:378:in `rescue in pull'
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:312:in `pull'
  /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:21:in `parse'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:233:in `build'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:42:in `initialize'
  -e:1:in `new'
  -e:1:in `<main>'
  ...
  #<ArgumentError: character encodings differ>
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:350:in `scan'
  /tmp/local/lib/ruby/1.9/rexml/parsers/baseparser.rb:350:in `pull'
  /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:21:in `parse'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:233:in `build'
  /tmp/local/lib/ruby/1.9/rexml/document.rb:42:in `initialize'
  -e:1:in `new'
  -e:1:in `<main>'
  ...
  Exception parsing
  Line: 
  Position: 
  Last 80 unconsumed characters:

  Line: 
  Position: 
  Last 80 unconsumed characters:
          from /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:90:in `rescue in parse'
          from /tmp/local/lib/ruby/1.9/rexml/parsers/treeparser.rb:19:in `parse'
          from /tmp/local/lib/ruby/1.9/rexml/document.rb:233:in `build'
          from /tmp/local/lib/ruby/1.9/rexml/document.rb:42:in `initialize'
          from -e:1:in `new'
          from -e:1:in `<main>'


# REXMLのこのエラーの出し方(扱い方)もどうかとは思いますが。


In This Thread

Prev Next