Fix stripos error when using Contains filter

Created on 17 July 2024, 5 months ago

Problem/Motivation

When using Contains for a search filter was getting this error:

TypeError: stripos(): Argument #2 ($needle) must be of type string, array given in stripos() (line 681 of /app/web/modules/contrib/views_csv_source/src/Query/Select.php).

Steps to reproduce

Use Contains for a filter on a CSV field and this error message will occur.

Proposed resolution

Contains passes an array, so just need to ensure that `verifyCondition` in `Select.php` is accessing the string within the array.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada nkind

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

Merge Requests

Comments & Activities

  • Issue created by @nkind
  • Merge request !9fix stripos error on contains filter β†’ (Merged) created by nkind
  • Status changed to Needs review 5 months ago
  • πŸ‡¨πŸ‡¦Canada nkind
  • Pipeline finished with Success
    5 months ago
    Total: 193s
    #227040
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Thanks for reporting this issue and providing a patch, @nkind! However, I'm unable to replicate it. Can you tell me a little more about your system (PHP version, etc.)? I've tried on PHP 8.1 and 8.3, but I'm not see it. Here's my View (you should be able to able to import this using Config Sync to test):

    langcode: en
    status: true
    dependencies:
      module:
        - views_csv_source
    id: csv
    label: CSV
    module: views
    description: 'Testing Views CSV Source'
    tag: ''
    base_table: csv
    base_field: ''
    display:
      default:
        id: default
        display_title: Default
        display_plugin: default
        position: 0
        display_options:
          title: CSV
          fields:
            value:
              id: value
              table: csv
              field: value
              relationship: none
              group_type: group
              admin_label: ''
              entity_type: null
              entity_field: null
              plugin_id: views_csv_source_field
              label: State
              exclude: false
              alter:
                alter_text: true
                text: '{{ value }}'
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              key: 'Geography Name'
              trusted_html: 0
            value_2:
              id: value_2
              table: csv
              field: value
              relationship: none
              group_type: sum
              admin_label: ''
              plugin_id: views_csv_source_field
              label: Male
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              key: 'Male (N)'
              trusted_html: 0
            value_3:
              id: value_3
              table: csv
              field: value
              relationship: none
              group_type: sum
              admin_label: ''
              plugin_id: views_csv_source_field
              label: Female
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              key: 'Female (N)'
              trusted_html: 0
          pager:
            type: none
            options:
              offset: 0
          exposed_form:
            type: basic
            options:
              submit_button: Apply
              reset_button: false
              reset_button_label: Reset
              exposed_sorts_label: 'Sort by'
              expose_sort_order: true
              sort_asc_label: Asc
              sort_desc_label: Desc
          access:
            type: none
            options: {  }
          cache:
            type: tag
            options: {  }
          empty: {  }
          sorts:
            value:
              id: value
              table: csv
              field: value
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: views_csv_source_sort
              order: ASC
              expose:
                label: ''
                field_identifier: ''
              exposed: false
              key: country
          arguments: {  }
          filters: {  }
          style:
            type: table
            options:
              grouping: {  }
              row_class: ''
              default_row_class: true
              columns:
                value: value
                value_2: value_2
                value_3: value_3
              default: '-1'
              info:
                value:
                  sortable: false
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                value_2:
                  sortable: false
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                value_3:
                  sortable: false
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
              override: true
              sticky: false
              summary: ''
              empty_table: false
              caption: ''
              description: ''
          row:
            type: fields
          query:
            type: views_query
            options:
              csv_file: 'https://data.hrsa.gov//DataDownload/DD_Files/AHRF_Diversity_Dashboard_Download_2016-2020.csv'
              headers: ''
              request_method: get
              request_body: ''
              show_errors: 1
          relationships: {  }
          group_by: true
          header: {  }
          footer: {  }
          display_extenders: {  }
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
          tags: {  }
      page_2:
        id: page_2
        display_title: 'Countries Containing "ai"'
        display_plugin: page
        position: 2
        display_options:
          fields:
            value:
              id: value
              table: csv
              field: value
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: views_csv_source_field
              label: country
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              key: country
              trusted_html: 0
          filters:
            value:
              id: value
              table: csv
              field: value
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: views_csv_source_filter
              operator: contains
              value: ia
              group: 1
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              key: country
          filter_groups:
            operator: AND
            groups: {  }
          style:
            type: table
            options:
              grouping: {  }
              row_class: ''
              default_row_class: true
              columns:
                value: value
              default: '-1'
              info:
                value:
                  sortable: false
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
              override: true
              sticky: false
              summary: ''
              empty_table: false
              caption: ''
              description: ''
          row:
            type: fields
            options: {  }
          query:
            type: views_query
            options:
              csv_file: 'https://extranet.who.int/tme/generateCSV.asp?ds=ltbi_estimates'
              headers: ''
              request_method: get
              request_body: ''
              show_errors: 1
          defaults:
            query: false
            style: false
            row: false
            fields: false
            filters: false
            filter_groups: false
          display_description: ''
          display_extenders: {  }
          path: ia-countries
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
          tags: {  }
    
    
  • πŸ‡¨πŸ‡¦Canada nkind

    Hey @andileco

    Sorry for the delayed response, i was away for a bit.

    I haven't been able to test your view yet, but the immediate difference I can see is that I'm using better exposed filters in my use case so it may be related to that which means that the small fix here may cause an issue with views not using bef, I'd have to verify that though. Also, for php I'm on version 8.2.

  • πŸ‡ΊπŸ‡ΈUnited States jackfoust

    MR9 works for me. PHP 8.3 & Drupal 10.3.5. Not using BEF. I do believe there are also errors with the "starts with" and "ends with" when exposed, I'm debugging.

  • πŸ‡ΊπŸ‡ΈUnited States jackfoust

    MR9 no longer works with 1.0.4, adding new patch.

  • πŸ‡ΊπŸ‡ΈUnited States andileco

    @jackfoust - we've been unable to recreate this error. Can you export your view and send a dummy CSV file (not real data) so that we can try to recreate it?

  • πŸ‡ΊπŸ‡ΈUnited States jackfoust

    Sounds great, thanks @andileco!

  • πŸ‡ΊπŸ‡ΈUnited States andileco

    @jackfoust can you try this instead and report back? https://git.drupalcode.org/project/views_csv_source/-/merge_requests/9/d...

  • πŸ‡¨πŸ‡¦Canada nkind

    Sorry I never got back around to this, thanks for following up on it @andileco

  • πŸ‡ΊπŸ‡ΈUnited States jackfoust

    Hi @andileco, as far as I can tell this resolves exposed contains and starts with/end with filters.

  • Pipeline finished with Skipped
    2 months ago
    #304170
  • πŸ‡ΊπŸ‡ΈUnited States andileco
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024