Page MenuHomePhabricator

TemplateData editor fails catastrophically when data contains $1
Closed, ResolvedPublic1 Estimated Story Points

Description

Because we use a regex replace function to switch the result back in:

'<t>foo $1 bar</t>'.replace( /(<t>)([\s\S]*?)(<\/t>)/, '<t> new $1 data </t>' );
> '<t> new <t> data </t>'

This template contains US$1,000,000 as an example value: https://en.wikipedia.org/w/index.php?title=Template:Infobox_company/doc

Event Timeline

Jdforrester-WMF added a project: VisualEditor.
Jdforrester-WMF set the point value for this task to 1.

Suggested workaround: make all subexpressions in the regex non-capturing:

'<t>foo $1 bar</t>'.replace( /(?:<t>)(?:[\s\S]*?)(?:<\/t>)/, '<t> new $1 data </t>' );
"<t> new $1 data </t>"

This is the quickest fix. Ideally we'd just use offset splices.

Change 272958 had a related patch set uploaded (by Jforrester):
Remove matching groups from regex

https://gerrit.wikimedia.org/r/272958

Change 272958 merged by jenkins-bot:
Remove matching groups from regex

https://gerrit.wikimedia.org/r/272958