misskey icon indicating copy to clipboard operation
misskey copied to clipboard

"register_note_post_interruptor" makes unexpected error in Misskey 12.120.0-alpha.8

Open maka8926 opened this issue 3 years ago • 1 comments

💡 Summary

New Deep-Copy function copies null fields when sending notes, that causing errors on API endpoints.

🥰 Expected Behavior

Notes should be sent with no error in while using register_note_post_interruptor

🤬 Actual Behavior

When a note is sent via API, it should be remove null in the nullable field, but if register_note_post_interruptor is used, null is not removed from the request body.

If it's normal, make a request like this: (no polls, no media, no CW, not a reply or renote quote.)

{"text":"Test Text", "poll":null, "localOnly":false, "visibility":"home", "i":"token"}

But it works like this:

{"text":"Test Text", "fileIds":null, "replyId":null, "renoteId":null ,"channelId":null, "poll":null, "cw":null, "localOnly":false, "visibility":"home", "visibleUserIds":null, "i":"token"}

This causes a null to enter a non-nullable field and causes an API error that prevents the note from being sent properly.

Its seems to be a problem caused by the new Deep-Copy function instead of the Deep-Copy usede before by Misskey. The existing JSON.parse(JSON.stringfiy()) deletes the null field of the structure during the parsing process, but the new function copies the null field without deleting it.

That problem causes the interruptor.handler function in MkPostForm to deep-copy a structure containing null to return a value containing null. This causes error in API Endpoint with non-nullable field, so backend returns an error.

📝 Steps to Reproduce

  1. Install and use a plugin that uses register_note_post_interruptor
### {
  id: "shxmwkehdRhflakf"
  name: "auto footer plugin"
  version: "1.0.0"
  author:  "@[email protected]"
  description: "Add footer automatically in notes."
  permissions: []
  config: {
    footer: {
      type: "string"
      label: "Footer"
      description: "Add a footer automatically after the double line break."
      default: ""
    }
  }
}

@note_with_footer(note) {
  #footer = Plugin:config.footer
  note.text <- `{note.text}{Str:lf}{Str:lf}{footer}`
  note
}

Plugin:register_note_post_interruptor(note_with_footer)
  1. Its make error like this: image

📌 Environment

Misskey version: Misskey 12.120.0-alpha.8 Your OS: Microsoft Windows 11 Home Insider Preview (25236.1010) Your browser: Mozilla Firefox Nightly 109.0a1

maka8926 avatar Nov 20 '22 10:11 maka8926

This issue is related to this commit.

maka8926 avatar Nov 20 '22 11:11 maka8926

@syuilo

tamaina avatar Dec 05 '22 11:12 tamaina

syuilo avatar Dec 06 '22 03:12 syuilo

これどうなりましたか? 一部フォークでは解決策が見つかり修正したみたいです

CyberRex0 avatar Nov 05 '23 10:11 CyberRex0

AiScriptに渡したときに、どこかのタイミングでundefinedがnullとして扱われているようです。 JSON.parse(JSON.stringify(obj)) ではundefinedが完全に無視されていたので、同じように無視する実装にすれば良いと思います。

https://github.com/taiyme/misskey/commit/4f7fbb69792e0e28f767c6b0e6fb7aae99cbe9ff

taiyme avatar Nov 05 '23 11:11 taiyme

要はこの問題はnullableでない値がnullに変換されてしまっていることが原因なので、それをどうにかすれば解決すると思います。 自分のforkではdeepClone関数でundefinedを弾くことで解決しましたが、連想配列からundefinedな値を除去する関数を間に挟むことでも解決できます。

taiyme avatar Nov 05 '23 11:11 taiyme