Fix IO#gets(limit) for encoding-related corner case
Merge pull request #2819 from ryoqun/io-gets-limit-encoding

Fix IO#gets(limit) for encoding-related corner case