Problem/Motivation

Hi, in the submission part of a webform, there is an input with the placeholder "Enter submitted to... which allows you to search different entity types to find the submissions concerned.

I noticed that if for example, an entity type which would be a node, had parentheses in its name (example: "NODE (23/2)"), the node sought would be 23/2 and not the id of the node.

Steps to reproduce

Create an attached entity type with parenthesis at the end of name.

Proposed resolution

Modifie the regex present in submitForm

- \( matches an opening parenthesis.

- [^()]+ matches one or more characters that are not opening or closing parentheses.

- \) matches a closing parenthesis.

- $ means the match should end at the end of the string.

This expression should always capture the content between the last parentheses without including the preceding parentheses.

If we dpm($matches) in the function submitForm() for the example "NODE (23/2)"

Before :
array:2 [▼
0 => "(23/2)"
1 => "23/2"
]

After :
array:1 [▼
0 => "node:598"
]

CommentFileSizeAuthor
regex_submit_form_1.patch730 bytesalexl

Issue fork webform-3423007

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

alexl created an issue. See original summary.

alexl’s picture

Issue summary: View changes
jrockowitz’s picture

I think only the regex needs to be improved by adding the $ and maybe allow for extra spaces.

Before

if (!empty($query['entity']) && preg_match('#\(([^)]+)\)#', $query['entity'], $match)) {

After

if (!empty($query['entity']) && preg_match('#\(([^)]+)\)\s*$#', $query['entity'], $match)) {

alexl’s picture

hi @jrockowitz

the string is give by my client and can have an open and not closed parenthesis. ex : "test (7/ "

I think my last regex covers all cases.

jrockowitz’s picture

Status: Needs review » Fixed

  • 0beb3959 committed on 6.2.x
    Issue #3423007 by alexl: Regex Submit Form for Enter Submitted to
    

Status: Fixed » Closed (fixed)

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