Skip to content

Commit 2643750

Browse files
committed
refs #51 - percent encode \r and \n in manifest file names
1 parent 0d245bc commit 2643750

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/main/java/gov/loc/repository/bagit/impl/ManifestReaderImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void setNext()
7171
} else if (filepath.indexOf('\\') != -1) {
7272
throw new UnsupportedOperationException(MessageFormat.format("This Library does not support \\ in filepaths: {0}. See README.txt.", filepath));
7373
}
74-
filepath = FilenameHelper.normalizePath(filepath);
74+
filepath = decode(FilenameHelper.normalizePath(filepath));
7575
log.trace("Filepath after normalization: " + filepath);
7676
this.next = new FilenameFixity(filepath, splitString[0]);
7777
log.debug("Read: " + this.next);
@@ -87,6 +87,11 @@ private void setNext()
8787

8888
}
8989

90+
//decode percent encoded \r and \n
91+
protected String decode(String filepath){
92+
return filepath.replaceAll("%0A", "\n").replaceAll("%0D", "\r");
93+
}
94+
9095
public FilenameFixity next() {
9196
if (this.next == null)
9297
{

src/main/java/gov/loc/repository/bagit/impl/ManifestWriterImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ public ManifestWriterImpl(OutputStream out, String separator) {
3030
}
3131

3232
public void write(String file, String fixityValue) {
33-
this.writer.println(fixityValue + separator + file);
33+
this.writer.println(fixityValue + separator + encode(file));
3434
log.debug(MessageFormat.format("Wrote to manifest: Filename is {0}. Fixity is {1}.", file, fixityValue));
3535
}
3636

37+
//percent encode \r and \n
38+
protected String encode(String file){
39+
return file.replaceAll("\n", "%0A").replaceAll("\r", "%0D");
40+
}
41+
3742
public void write(String file, String fixityValue, String _separator) {
3843
if(_separator != null){
3944
this.separator = _separator;

0 commit comments

Comments
 (0)