Skip to content

Commit

Permalink
#getFullPath was not correctly identifying non-existing assets depend…
Browse files Browse the repository at this point in the history
…ing on the name.
  • Loading branch information
jeluard committed May 16, 2013
1 parent fcaadf9 commit be05d76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/webjars/WebJarAssetLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public WebJarAssetLocator(final SortedMap<String, String> fullPathIndex) {
this.fullPathIndex = fullPathIndex;
}

private String throwNotFoundException(final String partialPath) {
throw new IllegalArgumentException(
partialPath
+ " could not be found. Make sure you've added the corresponding WebJar and please check for typos.");
}

/**
* Given a distinct path within the WebJar index passed in return the full
* path of the resource.
Expand All @@ -200,14 +206,16 @@ public String getFullPath(final String partialPath) {
.tailMap(reversePartialPath);

if (fullPathTail.size() == 0) {
throw new IllegalArgumentException(
partialPath
+ " could not be found. Make sure you've added the corresponding WebJar and please check for typos.");
throwNotFoundException(partialPath);
}

final Iterator<Entry<String, String>> fullPathTailIter = fullPathTail
.entrySet().iterator();
final String fullPath = fullPathTailIter.next().getValue();
final Entry<String, String> fullPathEntry = fullPathTailIter.next();
if (!fullPathEntry.getKey().startsWith(reversePartialPath)) {
throwNotFoundException(partialPath);
}
final String fullPath = fullPathEntry.getValue();

if (fullPathTailIter.hasNext()
&& fullPathTailIter.next().getKey()
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/webjars/WebJarAssetLocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public void get_full_path_from_partial_path_with_folders() {

@Test
public void should_throw_exception_when_asset_not_found() {
try {
new WebJarAssetLocator().getFullPath("asset-unknown.js");
fail("Exception should have been thrown!");
} catch (IllegalArgumentException e) {
assertEquals("asset-unknown.js could not be found. Make sure you've added the corresponding WebJar and please check for typos.", e.getMessage());
}

try {
new WebJarAssetLocator().getFullPath("unknown.js");
fail("Exception should have been thrown!");
Expand Down

0 comments on commit be05d76

Please sign in to comment.