Skip to content

Commit

Permalink
Merge pull request #200 from bjagg/fix/windows-paths
Browse files Browse the repository at this point in the history
fix: force unix path separator and EoL
  • Loading branch information
bjagg authored Dec 17, 2021
2 parents ba5366f + 0745415 commit 230532c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

/**
* Utility for determining the relative path between two files.
*
* @author Eric Dalquist
* @version $Revision$
* This is used for web URLs, so Windows backslash should not be used.
*/
public class RelativePath {

public static final String separator = "/";
/**
* break a path down into individual elements and add to a list.
* example : if a path is /a/b/c/d.txt, the breakdown will be [d.txt,c,b,a]
Expand Down Expand Up @@ -75,14 +75,14 @@ private static String matchPathLists(List<String> basePath, List<String> filePat

// for each remaining level in the home path, add a ..
for (; basePathItr.hasPrevious(); basePathItr.previous()) {
relativePath.append("..").append(File.separator);
relativePath.append("..").append(separator);
}

// for each level in the file path, add the path
while (filePathItr.hasPrevious()) {
relativePath.append(filePathItr.previous());
if (filePathItr.hasPrevious()) {
relativePath.append(File.separator);
relativePath.append(separator);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
*/
package org.jasig.resource.aggr;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
Expand Down Expand Up @@ -364,9 +355,11 @@ protected <T extends BasicInclude> T aggregateList(final MessageDigest digest, f
}
final Reader resourceIn = new InputStreamReader(bomIs, this.encoding);
if (element.isCompressed()) {
IOUtils.copy(resourceIn, trimmingWriter);
}
else {
final String resourceStr = IOUtils.toString(resourceIn);
final String resourceEolFix = resourceStr.replaceAll("\\r", "");
final InputStream isEolFix = IOUtils.toInputStream(resourceEolFix, this.encoding);
IOUtils.copy(isEolFix, trimmingWriter, this.encoding);
} else {
callback.compress(resourceIn, trimmingWriter);
}
}
Expand All @@ -376,7 +369,7 @@ protected <T extends BasicInclude> T aggregateList(final MessageDigest digest, f
finally {
IOUtils.closeQuietly(fis);
}
trimmingWriter.write(SystemUtils.LINE_SEPARATOR);
trimmingWriter.write(IOUtils.LINE_SEPARATOR_UNIX); // Needs to be consistent regardless of OS
}
}
finally {
Expand Down Expand Up @@ -460,7 +453,7 @@ protected String generatePathList(final Collection<? extends BasicInclude> eleme
*
* 2 {@link Css} objects are aggregatable if and only if:
* <ol>
* <li>Neither object returns true for {@link #isAbsolute()}</li>
* <li>Neither object returns true for isAbsolute()</li>
* <li>The values of their "conditional" properties are equivalent</li>
* <li>The values of their "media" properties are equivalent</li>
* <li>The "paths" of their values are equivalent</li>
Expand Down Expand Up @@ -498,15 +491,16 @@ protected boolean willAggregateWith(Css first, Css second) {
*
* 2 {@link Js} objects are aggregatable if and only if:
* <ol>
* <li>Neither object returns true for {@link #isAbsolute()}</li>
* <li>Neither object returns true for isAbsolute()</li>
* <li>The values of their "conditional" properties are equivalent</li>
* </ol>
*
* The last rule mentioned above uses {@link FilenameUtils#getFullPath(String)}
* to compare each object's value. In short, the final file name in the value's path
* need not be equal, but the rest of the path in the value must be equal.
*
* @param other
* @param first
* @param second
* @return
*/
protected boolean willAggregateWith(Js first, Js second) {
Expand Down

0 comments on commit 230532c

Please sign in to comment.