Skip to content

Commit

Permalink
Specify an input encoding to NKF to avoid misjudgement
Browse files Browse the repository at this point in the history
NKF sometimes misjudges an encoding. For example `カソウシテン` isn't
judged correctly.

```ruby
NKF.guess('カソウシテン'.encode("Windows-31J"))
=> #<Encoding:EUC-JP>
```

This causes misconverting. The previous word converts like this.

```ruby
NKF.nkf('-w', 'カソウシテン'.encode("Windows-31J"))
=> "郷骸竹"
```

The specifying input encoding prevent this.

```ruby
NKF.nkf('-S -w', 'カソウシテン'.encode("Windows-31J"))
=> "カソウシテン"
```

Fixes #33.
  • Loading branch information
y-yagi committed May 2, 2023
1 parent cb2c24a commit 2ad623a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def api(path, args = {}, verb = "post", options = {}, &error_checking_block)
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten
response = Hash[*key_values]
# converting to UTF-8
body = response = Hash[response.map { |k,v| [k, NKF.nkf('-w',v)] }]
body = response = Hash[response.map { |k,v| [k, NKF.nkf('-S -w',v)] }]
# Check for errors if provided a error_checking_block
yield(body) if error_checking_block
# Return result
Expand Down

0 comments on commit 2ad623a

Please sign in to comment.