Bug 37660 - using replace with <replacetoken>&#10;</replacetoken>
Summary: using replace with <replacetoken>&#10;</replacetoken>
Status: RESOLVED DUPLICATE of bug 22661
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.5
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-28 08:40 UTC by jiuding
Modified: 2008-12-05 02:21 UTC (History)
0 users



Attachments
test case(build file, two needed files), patch (5.44 KB, patch)
2005-11-28 08:56 UTC, jiuding
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jiuding 2005-11-28 08:40:24 UTC
Hello:
    Recently in my work, I needed to change all the ‘\n’ to ‘\nSomeWords’. I 
wrote the build file as following:
<project name="xxx-test" basedir="." default="test1">
  
  <target name="test1">
    
    <copy file="originalForReplaced.txt" tofile="forReplaced.txt" 
overwrite="true">
    </copy>
    <replace file="forReplaced.txt" value="&#10;SomeWords" >
      <replacetoken>&#10;</replacetoken>
    </replace>
  </target>

</project>

originalForReplaced.txt

hello
world

note:between the hello and world is '\n' not '\r\n'

	But failed. I looked into the source code, discovered that the string 
to be replaced and to be replaced with have all been processed so that ‘\n’ are 
replaced with ‘\r\n’. but the string contains the whole text is not processed. 
So if the lines of the text are terminated with ‘\n’, all the line breaks will 
not be replaced. Then I added the code of:

	newString = stringReplace(newString, "\r\n","\n", false);
        newString = stringReplace(newString, "\n", StringUtils.LINE_SEP, false);

in org.apache.tools.ant.taskdefs.Replace.processFile
the problem is resolved.
Comment 1 jiuding 2005-11-28 08:56:26 UTC
Created attachment 17061 [details]
test case(build file, two needed files), patch
Comment 2 Stefan Bodewig 2008-12-05 02:21:11 UTC

*** This bug has been marked as a duplicate of bug 22661 ***