A query string such as edit[field_project][widget][0][target_id]=123 gets changed to ?edit%5Bfield_project%5D%5Bwidget%5D%5B0%5D%5Btarget_id%5D=123 on output.

This is a problem when used in conjunction with modules like prepopulate which expect field structure to be passed in the query string.

Comments

theshanergy created an issue. See original summary.

laboratory.mike’s picture

OK, I've tried making the following view, and I cannot reproduce the character encoding issue. I've added the configuration below. If you could, please send me the modules and configuration of the view, so I can get an idea of how you are building the URL.

langcode: en
status: true
dependencies:
  config:
    - core.entity_view_mode.node.teaser
    - system.menu.main
  module:
    - node
    - user
    - views_add_button
id: vab_dev
label: 'VAB Development'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: tag
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      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
      pager:
        type: mini
        options:
          items_per_page: 10
          offset: 0
          id: 0
          total_pages: null
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          tags:
            previous: ‹‹
            next: ››
      style:
        type: default
      row:
        type: 'entity:node'
        options:
          view_mode: teaser
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          entity_type: node
          entity_field: title
          label: ''
          alter:
            alter_text: false
            make_link: false
            absolute: false
            trim: false
            word_boundary: false
            ellipsis: false
            strip_tags: false
            html: false
          hide_empty: false
          empty_zero: false
          settings:
            link_to_entity: true
          plugin_id: field
          relationship: none
          group_type: group
          admin_label: ''
          exclude: 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_alter_empty: true
          click_sort_column: value
          type: string
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
      filters:
        status:
          value: '1'
          table: node_field_data
          field: status
          plugin_id: boolean
          entity_type: node
          entity_field: status
          id: status
          expose:
            operator: ''
          group: 1
      sorts:
        created:
          id: created
          table: node_field_data
          field: created
          order: DESC
          entity_type: node
          entity_field: created
          plugin_id: date
          relationship: none
          group_type: group
          admin_label: ''
          exposed: false
          expose:
            label: ''
          granularity: second
      title: 'VAB Development'
      header:
        views_add_button:
          id: views_add_button
          table: views
          field: views_add_button
          relationship: none
          group_type: group
          admin_label: ''
          empty: false
          tokenize: 0
          type: node+article
          render_plugin: ''
          access_plugin: ''
          context: ''
          button_text: '+ Add Article'
          button_classes: 'btn btn-success button'
          button_attributes: ''
          button_access_denied:
            value: ''
            format: basic_html
          button_prefix:
            value: ''
            format: basic_html
          button_suffix:
            value: ''
            format: basic_html
          query_string: 'edit[body][0][value]=123'
          destination: 1
          plugin_id: views_add_button_area
      footer: {  }
      empty: {  }
      relationships: {  }
      arguments: {  }
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  page_1:
    display_plugin: page
    id: page_1
    display_title: Page
    position: 1
    display_options:
      display_extenders: {  }
      path: vab-development
      menu:
        type: normal
        title: 'VAB Development'
        description: ''
        expanded: false
        parent: ''
        weight: 0
        context: '0'
        menu_name: main
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
jason.bell’s picture

I have not experienced this with a single query string, but when trying to add multiples joined by an ampersand.

Update the above to query_string: 'edit[body][0][value]=123&plan=181', and it becomes edit[body][0][value]=123&amp%3Bplan=181 and does not work. Firefox leaves the first string alone and converts the ampersand to HTML entity, Chrome converts all of the punctuation characters.

laboratory.mike’s picture

@jason.bell, thanks for the insight. I'll try out that case.

laboratory.mike’s picture

Issue tags: +browser compatibility

I am adding a "Browser compatibility" tag to this, as its working fine for me in Firefox, even with something complex like this:

edit[body][0][value]=123&edit[body][0]["format"]=321

However, This does not work at all in Chrome. I'll see what I need to do to encode correctly.

  • laboratory.mike authored acb4b8f on 8.x-1.x
    Issue #3095849 by laboratory.mike, theshanergy, jason.bell: Query string...
laboratory.mike’s picture

Status: Active » Fixed

OK, figured it out. I needed to change how rendering works for the module (namely, the link has to be converted to a markup and string replacement performed), and I added bracket replacement only. We could do other characters, but I do not want to open it up to conversion of any character, to prevent from malicious characters being decoded.

The issue was, I was returning a render array for the link, and during conversion it appears that certain browsers encode the HTML entities in a query string. By returning a markup, I can enforce encoding of brackets.

Also, I tested the prefix/suffix HTML, and these are working the same as before.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

socialnicheguru’s picture

Component: Code » Code: Field Plugin

@laboratory.mike, how did you fix? version 1.8 does not have the fix above.