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

Floating point in fields is not working #14172

Closed
eloo-abi opened this issue Apr 17, 2019 · 2 comments · Fixed by #14412
Closed

Floating point in fields is not working #14172

eloo-abi opened this issue Apr 17, 2019 · 2 comments · Fixed by #14412

Comments

@eloo-abi
Copy link

Description:

Hi,
i've discovered a bug using incoming webhooks.
The bug occurs when a field with an value of type double is send. Then an error is thrown.
With wrapping the value in quotes it works, but the problem is that my system is not wrapping it. Also it works in Slack without quotes.

Steps to reproduce:

  1. Create incoming webhook without script
  2. Send message to incoming webhook with the following body
{
    "attachments": [
        {
            "color": "#D63232",
            "fallback": "[Alerting] My Alert",
            "fields": [
                {
                    "short": true,
                    "title": "Some value",
                    "value": 1.8503078660265208
                }
            ],
            "ts": 1555507262
        }
    ],
    "parse": "full"
}
  1. Send the same body with quotes around the numeric value of value and you see it working.

Expected behavior:

My alert is shown in RocketChat as expected

Actual behavior:

Then the following response will received and not message is coming up in the channel

{
    "success": false,
    "error": "Match error: Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation in field value"
}

Server Setup Information:

  • Version of Rocket.Chat Server: 0.74.3
  • Deployment Method: docker
  • Number of Running Instances: 1
  • MongoDB Version: 4.0.8
@eloo-abi eloo-abi changed the title Double as a value in fields is not working Floating point in fields is not working Apr 17, 2019
@eloo-abi
Copy link
Author

Looks like a script like this would fix the issue

/* exported Script */
/* globals console, _, s */

/** Global Helpers
 *
 * console - A normal console instance
 * _       - An underscore instance
 * s       - An underscore string instance
 */

class Script {
    /**
     * @params {object} request
     */
    process_incoming_request({ request }) {
      var content = request.content
      if(content.attachments)
      {
          var fields = content.attachments[0].fields
        for(var i in fields){
          fields[i]['value'] = fields[i]['value'].toString()
        }
      }
      return {
          content: request.content
        };
  
    }
  }

so maybe a simple toString() is missing somewhere

@ros-calumgilchrist
Copy link

Maybe this should be another issue, but I see similar issues with large numbers in the value field:
For example: 28363980800 errors but 28363980 does not.

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

Successfully merging a pull request may close this issue.

2 participants