Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Html::_namespaceInputs() to work with numbers as a namespace. #6656

Open
wants to merge 1 commit into
base: develop
from

Conversation

@timrosskamp
Copy link

@timrosskamp timrosskamp commented Aug 17, 2020

Description

The Html::_namespaceInputs() function can't take numbers as a namespace, because they break the regex replacement pattern. Numbers get concatenated with the capture reference, which changes the reference number.

Problem: '$1' . $namespace . '[$3]$4$2' turns into '$13[$3]$4$2' when $namespace = '3'. The reference $1 changed to $13.

This twig code

{{ '<input name="test">'|namespace('3')|raw }}

currently generates this html

<input [test]">

More info from php.net/manual/en/function.preg-replace

When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \1 notation for your backreference. \11, for example, would confuse preg_replace() since it does not know whether you want the \1 backreference followed by a literal 1, or the \11 backreference followed by nothing. In this case the solution is to use ${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.

Related issues

-/-

@brandonkelly brandonkelly force-pushed the craftcms:develop branch from f3e7059 to b5693f2 Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.