Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: force unix path separator and EoL #200

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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