C and Pure parser accept invalid UTF-8 strings, the Java parser doesn't.
まだ誰も着手していません。
評価
調査の方向性
まず Ruby の例を再現し、次に java/src/json/ext/ByteListTranscoder.java を読み、無効な UTF-8 に対する C、Pure、Java パーサーの動作を比較します。パーサーを変更する前に、どの動作が MRI と一致すべきかを明確にします。この入力に対して実装が合意された一貫した結果を返せば完了です。
索引モデルが issue の本文から書いたものです。
説明
I know, I know...if it's bad content it's bad content. But this represents a difference from MRI.
Here's the case, again a reduced version of one I got from @rkh:
# encoding: utf-8
require 'json'
x = "{\"foo\":\"\xC3\"}"
h = JSON.parse(x)
p h['foo']
p h['foo'].encoding
So basically there's a bad byte in a UTF-8 string, and the MRI version walks right by it and allows it to come through to the resulting parsed json structure.
I have a totally broken patch for this:
diff --git a/java/src/json/ext/ByteListTranscoder.java b/java/src/json/ext/ByteListTranscoder.java
index ed9e54b..a7e42ba 100644
--- a/java/src/json/ext/ByteListTranscoder.java
+++ b/java/src/json/ext/ByteListTranscoder.java
@@ -78,9 +78,10 @@ abstract class ByteListTranscoder {
return head;
}
if (head <= 0xbf) { // 0b10xxxxxx
- throw invalidUtf8(); // tail byte with no head
+ return head; //throw invalidUtf8(); // tail byte with no head
}
if (head <= 0xdf) { // 0b110xxxxx
+ if (pos + 1 > srcEnd) return head;
ensureMin(1);
int cp = ((head & 0x1f) << 6)
| nextPart();
Again, I'm not sure this is actually something that needs to be fixed, but because the MRI version of json does not blow up on this content, there's something to be addressed.
- 主要言語
- Ruby
- スター
- 782
- フォーク
- 383
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 10
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/json のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON. オープンjruby
-
jruby
似ている issue
-
SyncEm always forwards a dummy block, so wrapped methods lose their no-block/Enumerator behavior オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
endoflife-date/endoflife.date#11086 ·
-
internal
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
Kong/developer.konghq.com#7322 ·
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100