Skip to content

Commit

Permalink
BUGFIX: Support slashes in texts property
Browse files Browse the repository at this point in the history
Previously only single quotes were escaped in afx text nodes. This change
introduces a more generic escaping via addslashes that includes
slashes, single- and double-quotes. That way the rendered result of
afx will match the expectation better.

resolves: #2
  • Loading branch information
mficzel committed Nov 14, 2018
1 parent 5ff9f11 commit ef6d3d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Classes/Service/AfxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected static function astStringToFusion($payload, $indentation = '')
*/
protected static function astTextToFusion($payload, $indentation = '')
{
return '\'' . str_replace('\'', '\\\'', $payload) . '\'';
return '\'' . addslashes($payload) . '\'';
}

/**
Expand Down
34 changes: 34 additions & 0 deletions Tests/Functional/AfxServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,40 @@ public function spacesInsideALineArePreservedAlsoForStrings()
$this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode));
}

/**
* @test
*/
public function slashesInTextNodesArePreserved()
{
$afxCode = '<h1>\o/</h1>';

$expectedFusion = <<<'EOF'
Neos.Fusion:Tag {
tagName = 'h1'
content = '\\o/'
}
EOF;
$this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode));
}

/**
* @test
*/
public function textsAreEscaped()
{
$afxCode = <<<'EOF'
<h1>foo'bar\baz"bam</h1>
EOF;

$expectedFusion = <<<'EOF'
Neos.Fusion:Tag {
tagName = 'h1'
content = 'foo\'bar\\baz\"bam'
}
EOF;
$this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode));
}

/**
* @test
* @expectedException \PackageFactory\Afx\Exception
Expand Down

0 comments on commit ef6d3d0

Please sign in to comment.