裂缝中的错误?
我正在使用 Rubyoverflow gem,它允许通过 Ruby 代码使用 Stackoverflow API。我注意到有时我会收到错误消息:
Invalid JSON string
我尝试分析代码并发现当 Stackoverflow 的答案包含非 ascii 字符时会发生错误。
Rubyoverflow 使用 HTTParty gem,HTTParty gem 使用 Crack gem 解析 JSON 文件。
module Crack
class JSON
def self.parse(json)
json = json.delete!("^\u{0000}-\u{007F}") # here is my fix
YAML.load(unescape(convert_json_to_yaml(json)))
rescue ArgumentError => e
raise ParseError, "Invalid JSON string"
end
我添加了一行代码来从 JSON 中删除所有非 ASCII 字符,并且错误已修复。
现在我想了解我需要报告此错误的人是谁。
- 是否可以在 JSON 文档中包含非 ASCII 字符?
- 是否可以在 YAML 文档中包含非 ASCII 字符?
- 如果标准允许在 JSON 和 YAML 中包含非 ascii 字符 -> YAML 类中出现错误。对吗?这个类的作者是谁?修复这个错误的最佳方法是什么?
I am working with Rubyoverflow gem which allow to work with Stackoverflow API from Ruby code. And I noticed that sometimes I get error message:
Invalid JSON string
I have tried to analyze code and find out that the error occured when the Stackoverflow's answer has non ascii characters.
Rubyoverflow uses HTTParty gem, and HTTParty gem uses Crack gem to parse JSON files.
module Crack
class JSON
def self.parse(json)
json = json.delete!("^\u{0000}-\u{007F}") # here is my fix
YAML.load(unescape(convert_json_to_yaml(json)))
rescue ArgumentError => e
raise ParseError, "Invalid JSON string"
end
I have added one line of code to remove all non ascii characers from JSON and the error was fixed.
Now I want to understand who is the person I need to report about this error.
- Is it possible to include non ascii characters to JSON document?
- Is it possible to include non ascii characters to YAML document?
- If standarts allow to include non-ascii characters to JSON and YAML -> error in YAML class. Is it right? Who is the author of this class and which is the best way to fix this bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 和 YAML 文档应根据 HTTP 标头中给出的字符集进行解码,然后应适当地解析生成的文档。 JSON 和 YAML 都有一种用 ASCII 表达非 ASCII 字符的方法,但两者都没有强制要求使用它们,而不是使用完整的编码。
JSON and YAML documents should be decoded according to the charset given in the HTTP headers, and then the resulting document should be parsed appropriately. Both JSON and YAML do have a way of expressing non-ASCII characters in ASCII, but neither mandates their use as opposed to using a full encoding.