Modify

Ticket #208 (reopened defect)

Opened 4 years ago

Last modified 5 weeks ago

ReplaceRegexp problem with newline as replace string

Reported by: dthomas Owned by: hans
Priority: major Milestone: TBD
Component: phing-core Version: 2.3.0
Keywords: Cc:

Description

The documentation of the ReflexiveTask contains the following example:

<reflexive>

<fileset ... />
<filterchain>

<replaceregexp>

<regexp pattern="\n\r" replace="\n"/>

</replaceregexp>

</filterchain>

</reflexive>

But the modified files contain the string "\n" instead of the expected newline.

PS: shouldn't the pattern be "\r\n" instead for windows?

Attachments

Change History

comment:1 Changed 4 years ago by mrook

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in r346, thanks!

comment:2 Changed 8 months ago by michaelze

  • Status changed from closed to reopened
  • Resolution fixed deleted

I know this is a very old ticket, but in my opinion, this issue is not resolved.

I think the intention of the OP was not to hint the small mistake in the documentation but to point out that newlines in the replace attribute of the <regexp /> element do not appear as newlines in the replaced text but as the two characters "\" and "n".

Although this issue is over 3 years old, this still exists in v2.4.5.

comment:3 Changed 7 months ago by mrook

  • Milestone changed from 2.3.1 to TBD

comment:4 Changed 3 months ago by anonymous

It can be worked around by using:

<regexp pattern="\r\n" replace="${line.separator}"/>

comment:5 Changed 5 weeks ago by anonymous

${line.separator} returns the value of PHP_EOL which is \r\n on Windows. If you're processing files on Windows but do need \n (line feed) as line separator:

<php expression="chr(10)" returnProperty="LF"/>
...
<regexp pattern="\n\r" replace="${LF}"/> 
View

Add a comment

Modify Ticket

Action
as reopened
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.