Skip to content

Commit

Permalink
Made AssetsController Tests run on Windows again.
Browse files Browse the repository at this point in the history
Renamed an AssetsController Test to reflect correct behavior again.
Marked old AssetController method as obsolete.
  • Loading branch information
BjoernAkAManf committed Jun 25, 2015
1 parent 3422304 commit 424eb5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
23 changes: 17 additions & 6 deletions ninja-core/src/main/java/ninja/AssetsController.java
Expand Up @@ -224,7 +224,21 @@ private URL getStaticFileFromMetaInfResourcesDir(String fileName) {

return url;
}


/**
* This function mirrors legacy behavior of the AssetsController
*
* @param fileName A potential "fileName"
* @see #normalizePathWithoutLeadingSlash(java.lang.String, boolean)
* @deprecated This method was replaced and should not be used.
* @return A normalized fileName.
*/
@VisibleForTesting
@Deprecated
protected String normalizePathWithoutLeadingSlash(String fileName) {
return normalizePathWithoutLeadingSlash(fileName, false);
}

/**
* If we get - for whatever reason - a relative URL like
* assets/../conf/application.conf we expand that to the "real" path.
Expand All @@ -237,14 +251,11 @@ private URL getStaticFileFromMetaInfResourcesDir(String fileName) {
* possible.
*
* @param fileName A potential "fileName"
* @param enforceUnixSeparator Forces to normalise unix style
* @return A normalized fileName.
*/
@VisibleForTesting
protected String normalizePathWithoutLeadingSlash(String fileName) {
return normalizePathWithoutLeadingSlash(fileName, false);
}

private String normalizePathWithoutLeadingSlash(String fileName, boolean enforceUnixSeparator) {
protected String normalizePathWithoutLeadingSlash(String fileName, boolean enforceUnixSeparator) {
String fileNameNormalized = enforceUnixSeparator
? FilenameUtils.normalize(fileName, true)
: FilenameUtils.normalize(fileName);
Expand Down
16 changes: 8 additions & 8 deletions ninja-core/src/test/java/ninja/AssetsControllerTest.java
Expand Up @@ -249,13 +249,13 @@ public void testServeStaticRobotsTxt()
}

@Test
public void testNormalizePathWithoutTrailingSlash() {
assertEquals("dir1/test.test", assetsController.normalizePathWithoutLeadingSlash("/dir1/test.test"));
assertEquals("dir1/test.test", assetsController.normalizePathWithoutLeadingSlash("dir1/test.test"));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash("/../test.test"));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash("../test.test"));
assertEquals("dir2/file.test", assetsController.normalizePathWithoutLeadingSlash("/dir1/../dir2/file.test"));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash(null));
assertEquals("", assetsController.normalizePathWithoutLeadingSlash(""));
public void testNormalizePathWithoutLeadingSlash() {
assertEquals("dir1/test.test", assetsController.normalizePathWithoutLeadingSlash("/dir1/test.test", true));
assertEquals("dir1/test.test", assetsController.normalizePathWithoutLeadingSlash("dir1/test.test", true));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash("/../test.test", true));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash("../test.test", true));
assertEquals("dir2/file.test", assetsController.normalizePathWithoutLeadingSlash("/dir1/../dir2/file.test", true));
assertEquals(null, assetsController.normalizePathWithoutLeadingSlash(null, true));
assertEquals("", assetsController.normalizePathWithoutLeadingSlash("", true));
}
}

0 comments on commit 424eb5b

Please sign in to comment.