Skip to content

`split': invalid byte sequence in US-ASCII (ArgumentError) on ripper.rb #596

@github0013

Description

@github0013

Metadata

node -v
  v14.5.0

ruby -v
  ruby 2.7.1p83 (2020-03ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

uname -a
  Darwin mbp 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64

cat package.json
  {
    "devDependencies": {
      "@prettier/plugin-ruby": "^0.19.0",
      "prettier": "^2.0.5"
    }
  }

Visual Studio Code
  Version: 1.47.0
  Commit: d5e9aa0227e057a60c82568bf31c04730dc15dcd
  Date: 2020-07-09T08:01:54.115Z (1 wk ago)
  Electron: 7.3.2
  Chrome: 78.0.3904.130
  Node.js: 12.8.1
  V8: 7.8.279.23-electron.0
  OS: Darwin x64 19.6.0

https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
  v5.1.3

Input

# あ 

      d=[30644250780,9003106878,
  30636278846,66641217692,4501790980,
671_24_603036,131_61973916,66_606629_920,
 30642677916,30643069058];a,s=[],$*[0]
    s.each_byte{|b|a<<("%036b"%d[b.
       chr.to_i]).scan(/\d{6}/)}
        a.transpose.each{ |a|
          a.join.each_byte{\
           |i|print i==49?\
             ($*[1]||"#")\
               :32.chr}
                 puts
                  }
class RipperJS < Ripper
  attr_reader :source, :lines, :__end__

  def initialize(source, *args)
    super(source, *args)

    @source = source # <= source.encoding
    @lines = source.split("\n")
    @__end__ = nil
  end

It seems if ran through VSCode, source.encoding would be recognized as "US-ASCII." And I get an error like below.

ripper.rb:25:in `split': invalid byte sequence in US-ASCII (ArgumentError)

When I run bundle exec rbprettier --write on the same file, source.encoding is "UTF-8", and the format is done correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions