HomePhabricator

Fix validation of translation unit section names

Description

Fix validation of translation unit section names

The diff is minimal. The issue was that \n was escaped to \\n by
preg_quote. When placed into a brackets in a regular expression,
it would instead match a backlash and the letter n. Because custom
unit names are rarely used, this issue would go unnoticed for a
while. When using a literal newline character, the issue goes away.

A better fix would be to encapsulate this in a method with tests,
but the fact that this is also used in a [^] context would require
more refactoring, which would delay fixing the issue.

Correct behavior can be verified manually using this code:
$ic = preg_quote( "_/\n<>", '~');
var_dump( preg_match( "~[$ic]~", "a\na" ) );
var_dump( preg_match( "~[$ic]~", '<foo>' ) );
var_dump( preg_match( "~[$ic]~", 'this-contains-letter-n' ) );
var_dump( preg_match( "~[$ic]~", "aa" ) );
var_dump( preg_match( "~[$ic]~", "a\\a" ) );

First two match (aka fail), while the rest do not.

Bug: T263546
Change-Id: I9bb3defcbac043160c813b1ebd7185b27be71f05

Details

Provenance
NikerabbitAuthored on Sep 23 2020, 6:03 AM
abi_Committed on Sep 24 2020, 9:52 AM
Parents
rETRAfd79785cb276: Align translation stats graphs horizontally
Branches
Unknown
Tags
Unknown
References
wmf/1.36.0-wmf.10
ChangeId
I9bb3defcbac043160c813b1ebd7185b27be71f05