vap_num counts dots in HTML comments

Created on 2 December 2022, about 2 years ago
Updated 28 February 2023, almost 2 years ago

Problem/Motivation

When twig debugging is enabled, vap_num() will assume a dot in the html comment is the decimal one.

Steps to reproduce

Enable twig debugging and create a sum on a column containing a field with HTML comments.

Proposed resolution

First strip HTML comments from the string passed to vap_num.

Remaining tasks

Review patch.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium seutje Antwerp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    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.

  • πŸ‡§πŸ‡ͺBelgium seutje Antwerp

    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.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024