Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A single malformed post breaks scrollback #776

Open
jasom opened this issue Aug 19, 2022 · 2 comments
Open

A single malformed post breaks scrollback #776

jasom opened this issue Aug 19, 2022 · 2 comments

Comments

@jasom
Copy link
Contributor

jasom commented Aug 19, 2022

Due to blindsidenetworks/mattermost-plugin-bigbluebutton#225 there are malformed posts in my history. I don't expect matterhorn to handle malformed posts correctly, but given that plugins can currently insert malformed posts, I do expect to be able to view other posts even in the presence of such malformed posts.

This probably will need changes in matterhorn-api as well.

I don't have a reduced test-case, but injecting a post with from_webhook set to any non-string value should reproduce the issue readily.

If it's helpful, the errors I get are of the form JSONDecodeException {jsonDecodeExceptionMsg = "Error in $.posts.<id>.props['from_webhook']: parsing Text failed, expected String, but encountered boolean, jsonDecodeExceptionJSON = "{"order":[...]...}"

@jasom
Copy link
Contributor Author

jasom commented Aug 19, 2022

My current workaround for this is probably not appropriate for upstreaming, as it only works around the specific issue I encounter; it handles the correct form (string-as-bool) the same way currently, passes a bool through unmolested, and treats any other value as "false". I've included it below in any case.

I suspect the proper fix would involve changing the parsing of the Posts FromJSON to handle malformed posts in some appropriate manner, but my Haskell skills are not up to the task.

diff --git a/src/Network/Mattermost/Types.hs b/src/Network/Mattermost/Types.hs
index de62e65..113aa30 100644
--- a/src/Network/Mattermost/Types.hs
+++ b/src/Network/Mattermost/Types.hs
@@ -711,7 +711,10 @@ instance A.FromJSON PostProps where
     postPropsFromWebhookStr   <- v .:? "from_webhook"
     let postPropsFromWebhook = do
             s <- postPropsFromWebhookStr
-            return $ s == ("true"::Text)
+            return $ case s of 
+                        (A.Bool x)  -> x
+                        (A.String x) -> x == ("true"::Text)
+                        _ -> False
     postPropsAttachments      <- v .:? "attachments"
     postPropsNewHeader        <- v .:? "new_header"
     postPropsOldHeader        <- v .:? "old_header"

@jtdaugherty
Copy link
Member

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants