Skip to content

Commit

Permalink
Refs #1673 - add skipsanitize toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Apr 26, 2023
1 parent 98105d1 commit 383ad4e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
57 changes: 57 additions & 0 deletions etc/phing-grammar.rng
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<ref name="blockfor"/>
<ref name="chmod"/>
<ref name="chown"/>
<ref name="concat"/>
<ref name="condition"/>
<ref name="copy"/>
<ref name="delete"/>
Expand Down Expand Up @@ -1105,6 +1106,9 @@
<optional>
<attribute name="fixlastline"/>
</optional>
<optional>
<attribute name="skipsanitize"/>
</optional>
<optional>
<attribute name="eol"/>
</optional>
Expand Down Expand Up @@ -1413,6 +1417,59 @@
</element>
</define>

<define name="concat">
<element name="concat">
<optional>
<attribute name="destFile"/>
</optional>
<optional>
<attribute name="append"/>
</optional>
<optional>
<attribute name="overwrite"/>
</optional>
<optional>
<attribute name="fixlastline"/>
</optional>
<optional>
<attribute name="skipsanitize"/>
</optional>
<optional>
<attribute name="eol"/>
</optional>
<optional>
<attribute name="text"/>
</optional>
<optional>
<choice>
<attribute name="file"/>
<oneOrMore>
<interleave>
<optional>
<ref name="fileset"/>
</optional>
<optional>
<ref name="filelist"/>
</optional>
</interleave>
</oneOrMore>
</choice>
</optional>
<optional>
<ref name="filterchain"/>
</optional>
<optional>
<ref name="append-header"/>
</optional>
<optional>
<ref name="append-footer"/>
</optional>
<optional>
<ref name="path"/>
</optional>
</element>
</define>

<define name="condition">
<element name="condition">
<attribute name="property">
Expand Down
11 changes: 10 additions & 1 deletion src/Phing/Task/System/AppendTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class AppendTask extends Task

private $eolString;

private $skipSanitize = false;

public function setFiltering(bool $filtering): void
{
$this->filtering = $filtering;
Expand Down Expand Up @@ -217,6 +219,11 @@ public function setFixLastLine(bool $fixLastLine): void
$this->fixLastLine = $fixLastLine;
}

public function setSkipSanitize(bool $skipSanitize): void
{
$this->skipSanitize = $skipSanitize;
}

/**
* Append the file(s).
*
Expand Down Expand Up @@ -332,7 +339,9 @@ private function appendFooter($string): string

private function validate(): void
{
$this->sanitizeText();
if (!$this->skipSanitize) {
$this->sanitizeText();
}

if (null === $this->file && null === $this->text && 0 === count($this->filesets) && 0 === count($this->filelists)) {
throw new BuildException('You must specify a file, use a filelist/fileset, or specify a text value.');
Expand Down
7 changes: 7 additions & 0 deletions tests/Phing/Test/Task/System/AppendTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ public function testfixlastlineeol(): void
file_get_contents($this->getProject()->getProperty('basedir') . 'concat.linecr')
);
}

public function testSkipSanitize(): void
{
$this->executeTarget('testskipsanitize');
$contents = file_get_contents($this->getProject()->getProperty('basedir') . $this->tempFile);
$this->assertEquals("\n foo", $contents);
}
}
6 changes: 6 additions & 0 deletions tests/etc/tasks/system/AppendTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@
</concat>
</target>

<target name="testskipsanitize">
<concat destFile="${tmp.file}" text="${line.separator}" skipsanitize="true"/>
<concat destFile="${tmp.file}" text=" " skipsanitize="true"/>
<concat destFile="${tmp.file}" text="foo"/>
</target>

</project>

0 comments on commit 383ad4e

Please sign in to comment.