[
http://jira.codehaus.org/browse/JBEHAVE-389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mauro Talevi resolved JBEHAVE-389.
----------------------------------
Resolution: Fixed
> Spaces in Path breaks LoadFromRelativeFile
> ------------------------------------------
>
> Key: JBEHAVE-389
> URL: http://jira.codehaus.org/browse/JBEHAVE-389
> Project: JBehave
> Issue Type: Bug
> Components: Core
> Affects Versions: 3.0.3
> Environment: Redhat Linux 5.5
> Reporter: Leif Carlsen
> Assignee: Paul Hammant
> Priority: Minor
> Fix For: 3.2
>
>
> LoadFromRelativeFile function loadStoryAsTextfails to unescape URLs passed
> into the constructor that have escaped characters like %20 for a space. As a
> result, the story files cannot be found.
> Test case snippet follows... add it to StoryLoaderBehaviour.java. Also need
> to add folder "foldername has spaces" to
> jbehave-core/src/test/java/org/jbehave/core/io/stories/ and copy
> MyPendingStory.txt into it. Also including revised code snippet for
> loadStoryAsText function. I didn't immediately see a way to do it without
> either checked exceptions or deprecated functions (ex
> UrlDecoder.decode(string)). Not sure if InvalidStoryResource was the right
> exception to convert to.
> {code:title=StoryLoaderBehaviour.java}
> @Test
> public void shouldLoadStoryFromRelativeFilePathsWithSpace() throws
> MalformedURLException, URISyntaxException {
> // Given
> String storyPath = "MyPendingStory.txt";
> String storyAsText = "Given my step";
> java.net.URL url =
> CodeLocations.codeLocationFromClass(MyPendingStory.class);
> java.io.File folderWithSpacesInName = new
> java.io.File(url.toURI().getPath() + "/org/jbehave/core/io/stories/foldername
> has spaces");
> java.net.URL urlThatHasEscapedSpaces =
> folderWithSpacesInName.toURI().toURL();
> assertThat(folderWithSpacesInName.exists(), is(true));
> // When
> StoryLoader loader = new
> LoadFromRelativeFile(urlThatHasEscapedSpaces);
> // Then
> assertThat(loader.loadStoryAsText(storyPath), equalTo(storyAsText));
> }
> {code}
> {code:title=LoadFromRelativeFile.java}
> public String loadStoryAsText(String storyPath) {
> List<String> traversalPaths = new ArrayList<String>();
> String locationPath;
> try {
> locationPath = new
> File(URLDecoder.decode(location.getFile(),"UTF-8")).getAbsolutePath();
> } catch (UnsupportedEncodingException e) {
> throw new InvalidStoryResource(storyPath, e);
> }
> for (StoryFilePath traversal : traversals) {
> String filePath = locationPath.replace(traversal.toRemove,
> traversal.relativePath) + "/" + storyPath;
> File file = new File(filePath);
> if (file.exists()) {
> return loadContent(filePath);
> } else {
> traversalPaths.add(filePath);
> }
> }
> throw new StoryResourceNotFound(storyPath, traversalPaths);
> }
> {code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email