Skip to content

Malformed conversion of forms with relative action URLs #4208

@pierlon

Description

@pierlon

Bug Description

When a form element has a relative URL (such as ../) or a query (such as ?foo=bar) for the action attribute, the value is incorrectly sanitized and a malformed URL is produced.

For example, given that the request URL is https://example.org/about/?amp with Transitional mode active, the following can be observed:

action Sanitized action Expected action
../ //example.org/about/?amp/__/&_wp_amp_action_xhr_converted=1&amp //example.org/?amp&_wp_amp_action_xhr_converted=1
?foo=bar //example.org/about?amp?foo=bar&_wp_amp_action_xhr_converted=1&amp //example.org/about/?amp&foo=bar&_wp_amp_action_xhr_converted=1

This is also reproducible in Standard mode.

Do note that actions with relative anchor tags (eg. #foo) are correctly converted, which was fixed by #4003.

Steps to reproduce

  1. Activate Transitional mode

  2. Create a post and add a Custom HTML block with the following content:

<form method="post" action="../"></form> 
<form method="post" action="?foo=bar"></form> 
  1. View the AMP version of the post

  2. Given that the current URL is https://example.org/about/?amp, the following malformed action-xhr URL values for each form element can be observed:

<form method="post" action-xhr="//example.com/about/?amp/__/&_wp_amp_action_xhr_converted=1&amp">...</form>

<form method="post" action-xhr="//example.com/about/?amp?foo=bar&_wp_amp_action_xhr_converted=1&amp">...</form>

Screenshots

Additional context

  • WordPress version:
  • Plugin version:
  • Gutenberg plugin version (if applicable):
  • AMP plugin template mode:
  • PHP version:
  • OS:
  • Browser: [e.g. chrome, safari]
  • Device: [e.g. iPhone6]

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingQA passedHas passed QA and is doneSanitizers

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions