Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document sanitizing of text in Append task #1673

Closed
jawira opened this issue Apr 21, 2022 · 6 comments
Closed

Document sanitizing of text in Append task #1673

jawira opened this issue Apr 21, 2022 · 6 comments

Comments

@jawira
Copy link
Contributor

jawira commented Apr 21, 2022

I'm trying to add a final new line at the end of a file. I tried to do so with AppendTask.

<append destFile="my-file.txt" text="${line.separator}"/>

The problem is this doesn't work because text is "sanitized" after:

private function sanitizeText(): void
{
if (null !== $this->text && '' === trim($this->text)) {
$this->text = null;
}
}

I don't understand the rationale behind sanitizeText. But IMHO this method can be deleted, or maybe there's another way to simply append a new line ?

Thanks

@siad007
Copy link
Member

siad007 commented Apr 21, 2022

Hi @jawira did you try with fixLastLine Attribute set to true?

@jawira
Copy link
Contributor Author

jawira commented Apr 21, 2022

Hi @siad007 ! Thanks for replying :) I just tried to use fixLastLine but my build keeps failing:

BUILD FAILED
/home/jawira/PhpstormProjects/xxxxxx/build.xml:236:59 You must specify a file, use a filelist/fileset, or specify a text value.

Total time: 0.0444 seconds

I'm more curious about why sanitizeText is required? what if I just want to append white spaces?

I can make a PR if required. Since this is not very important, you can also close this issue if you want :)

@siad007 siad007 added the defect label Jun 29, 2022
@siad007
Copy link
Member

siad007 commented Jun 29, 2022

Hi @jawira - sry for that long delay.

Looking here a little bit closer, we have a bug here.

I'm more curious about why sanitizeText is required?

AFAIK This is needed against empty text arguments like <append destFile="my-file.txt" text=""/> (related also to xml parsing)

Things that should work are at least:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="test" default="one">
    <target name="one">
        <append destFile="my-file.txt" text="${line.separator}"/>
    </target>
    <target name="two">
        <append destFile="my-file.txt" text="
"/>
    </target>
    <target name="three">
        <append destFile="my-file.txt" text="&#10;"/>
    </target>
</project>

@mrook mrook added this to the 3.0.0-RC5 milestone Jan 25, 2023
@mrook
Copy link
Member

mrook commented Apr 5, 2023

Actually, this is by design and matches the way the Concat task works in Ant. This is because adding a nested text element may introduce additional (ignorable) whitespace. Hence the sanitizeText call at the start of validate. This is not well documented, and maybe we need to introduce a switch that can disable that behavior.

@mrook mrook changed the title Cannot add line to file Document sanitizing of text in Append task Apr 15, 2023
mrook added a commit that referenced this issue Apr 26, 2023
@mrook
Copy link
Member

mrook commented Apr 26, 2023

@mrook mrook closed this as completed Apr 26, 2023
@jawira
Copy link
Contributor Author

jawira commented Apr 28, 2023

@mrook thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants