Skip to content

Commit

Permalink
refs #51 - percent encode \r and \n in manifest file names
Browse files Browse the repository at this point in the history
  • Loading branch information
johnscancella committed Jun 23, 2016
1 parent 0d245bc commit 2643750
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void setNext()
} else if (filepath.indexOf('\\') != -1) {
throw new UnsupportedOperationException(MessageFormat.format("This Library does not support \\ in filepaths: {0}. See README.txt.", filepath));
}
filepath = FilenameHelper.normalizePath(filepath);
filepath = decode(FilenameHelper.normalizePath(filepath));
log.trace("Filepath after normalization: " + filepath);
this.next = new FilenameFixity(filepath, splitString[0]);
log.debug("Read: " + this.next);
Expand All @@ -87,6 +87,11 @@ private void setNext()

}

//decode percent encoded \r and \n
protected String decode(String filepath){
return filepath.replaceAll("%0A", "\n").replaceAll("%0D", "\r");
}

public FilenameFixity next() {
if (this.next == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ public ManifestWriterImpl(OutputStream out, String separator) {
}

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

//percent encode \r and \n
protected String encode(String file){
return file.replaceAll("\n", "%0A").replaceAll("\r", "%0D");
}

public void write(String file, String fixityValue, String _separator) {
if(_separator != null){
this.separator = _separator;
Expand Down

0 comments on commit 2643750

Please sign in to comment.