[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit MimeEncodedMessageBody.java,1.14,1.15
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-11-15 06:26:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv22418/src/com/meterware/httpunit
Modified Files:
MimeEncodedMessageBody.java
Log Message:
638408: convert line endings to CRLF in Mime encoded messages
Index: MimeEncodedMessageBody.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MimeEncodedMessageBody.java 31 Oct 2002 04:21:28 -0000 1.14
+++ MimeEncodedMessageBody.java 15 Nov 2002 02:53:59 -0000 1.15
@@ -109,7 +109,24 @@
writeLn( _outputStream, "Content-Disposition: form-data; name=\"" + name + '"' ); // XXX need to handle non-ascii names here
writeLn( _outputStream, "Content-Type: text/plain; charset=" + getRequest().getCharacterSet() );
writeLn( _outputStream, "" );
- writeLn( _outputStream, value, getRequest().getCharacterSet() );
+ writeLn( _outputStream, fixLineEndings( value ), getRequest().getCharacterSet() );
+ }
+
+
+ private final static char CR = 0x0D;
+ private final static char LF = 0x0A;
+
+ private String fixLineEndings( String value ) {
+ StringBuffer sb = new StringBuffer();
+ char[] chars = value.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ if (chars[i] == CR || (chars[i] == LF && (i == 0 || chars[i-1] != CR))) {
+ sb.append( CR ).append( LF );
+ } else {
+ sb.append( chars[i] );
+ }
+ }
+ return sb.toString();
}
|