Problem/Motivation

When using a field not provided by either views or views_webform, the getCell method will assume it should be rendered. If Twig debugging is enabled, this will contain HTML comments with dots in them, which will be interpreted by vap_num as decimal dots, throwing off the calculation entirely.

Steps to reproduce

- Have another module provide a field with a decimal number (like views_simple_math_field)
- Create a sum of that field.
- Enable Twig debugging.

Proposed resolution

Don't assume fields not provided by views or views_webform should be rendered first, or at least make sure they don't contain any markup when passing them to vap_num, especially when the $rendered parameter is set to FALSE.

Remaining tasks

Implement solution.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

seutje created an issue. See original summary.

seutje’s picture

Issue summary: View changes
Status: Active » Needs review
tr’s picture

Status: Needs review » Needs work

I guess my question is why is rendered HTML content being passed to vap_num() ?

function views_aggregator_get_cell($field_handler, $row_num, $rendered = FALSE)

When we use vap_num(), we use it like this:
vap_num(views_aggregator_get_cell($field_handler, $num, FALSE));
That is, we pass the NON-rendered cell content to vap_num().

So is the problem really with views_aggregator_get_cell() ?

The proposed solution feels like a hack, which just strips HTML comments and not other HTML tags - if comments are coming through shouldn't we be concerned with any other HTML as well?

Regardless, the only argument to vap_num() is "A string representatin of a double-precision floating point number.", so the problem really is that some code is passing in invalid data, because HTML comments have no business being passed in the first place.

If we want to validate the argument as a double-precision floating point number, then PHP provides is_float() and is_double() methods. We should validate the argument in vap_num(), but if an invalid argument is passed in that's the fault of the calling code.

seutje’s picture

Title: vap_num counts dots in HTML comments » views_aggregator\Plugin\views\style\Table->getCell assumes any field not provided by views or webform_views should be rendered
Issue summary: View changes

Yes, you are correct.

I noticed the issue when using a views_simple_math_field to multiply a price per piece with an amount and then create a sum of this multiplication. The user can create products, which have a price per piece and they can then reference these products in an order, adding an amount. I created an overview table to see the total price per order.
The issue occurs in views_aggregator/src/Plugin/views/style/Table.php on line 653, where !in_array($field_handler->getProvider(), ['views', 'webform_views']) evaluates to TRUE. So it seems like it assumes that any field not provided by Views or Webform Views should be rendered before being passed to vap_num, even when the $rendered parameter is set to FALSE, which would seem like a bit of a wild assumption.

tr’s picture

Version: 2.0.x-dev » 2.1.x-dev