Page MenuHomePhabricator

YAML output fails to literalize strings which start with \n
Closed, ResolvedPublic

Description

Author: kahrl

Description:
If a string starts with a newline but does trigger any other condition in Spyc::_needLiteral(), Spyc fails to write it to the YAML output as a literal (i.e. starting with |- and properly escaped). This is because strpos( $value, "\n" ) returns 0, which is interpreted as false. This bug causes Perl's YAML module and possibly other loaders to choke on the YAML.

The trivial fix is to change line 167 of phase3/includes/libs/spyc.php from

strpos( $value, "\n" ) ||

to

strpos( $value, "\n" ) !== false ||

Example of a query that triggers this bug:

http://de.guttenplag.wikia.com/api.php?action=query&format=yaml&prop=revisions&rvprop=content&titles=Benutzer:Kahrl/YamlBug

Example of a query that triggers but does not show this bug (because there's also a # in the string):

http://de.guttenplag.wikia.com/api.php?action=query&format=yaml&prop=revisions&rvprop=content&titles=Benutzer:Kahrl/YamlBug2


Version: 1.18.x
Severity: normal

Details

Reference
bz28416

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:32 PM
bzimport set Reference to bz28416.

kahrl wrote:

s/does trigger/does not trigger/, of course.

kahrl wrote:

Probably no longer needed due to r86302.

kahrl wrote:

(In reply to comment #4)

Is this reported to spyc?

It seems this has already been fixed upstream. http://code.google.com/p/spyc/source/browse/trunk/spyc.php uses "strpos($value,"\n") !== false" in _dumpNode().