Skip to content

Commit

Permalink
Handle spaces in path names
Browse files Browse the repository at this point in the history
- IT demonstrating failure when creating an object with a space in its path and then trying to perform a SPARQL update on it

Resolves: https://www.pivotaltracker.com/story/show/72296804
  • Loading branch information
escowles authored and Andrew Woods committed Jul 27, 2014
1 parent 94b9e94 commit 494ab59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Expand Up @@ -1689,4 +1689,19 @@ public void testLastModifiedUpdatedAfterUpdates() throws Exception {
assertFalse("Last-Modified headers should have changed", lastmod1 == lastmod2);
}

@Test
public void testUpdateObjectWithSpaces() throws Exception {
final String id = getRandomUniquePid() + " 2";
final HttpResponse createResponse = createObject(id);
final String subjectURI = createResponse.getFirstHeader("Location").getValue();
final HttpPatch updateObjectGraphMethod = new HttpPatch(subjectURI);
updateObjectGraphMethod.addHeader("Content-Type", "application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream(
"INSERT { <> <http://purl.org/dc/elements/1.1/title> \"test\" } WHERE {}".getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode());
}

}
Expand Up @@ -152,8 +152,13 @@ public boolean isCanonical() {
@Override
public Resource getSubject(final String absPath) throws RepositoryException {
resetTranslationChain();
LOGGER.debug("Creating RDF subject from identifier: {}", absPath);
return doForward(absPath);
if ( absPath != null && absPath.indexOf("%20") != -1 ) {

This comment has been minimized.

Copy link
@cbeer

cbeer Jul 28, 2014

Contributor

This comment has been minimized.

Copy link
@awoods

awoods Jul 28, 2014

Yes, using URLDecoder.decode() instead of String.replaceAll() seems more comprehensive.

This comment has been minimized.

Copy link
@escowles

escowles Jul 28, 2014

Author Contributor

Sure, we can do that:

#429

LOGGER.debug("Creating RDF subject from identifier with spaces: {}", absPath);
return doForward(absPath.replaceAll("%20"," "));
} else {
LOGGER.debug("Creating RDF subject from identifier: {}", absPath);
return doForward(absPath);
}
}

@Override
Expand Down
Expand Up @@ -123,7 +123,12 @@ public void addedStatement(final Statement s) {
skolemizedBnodeMap.put(subject.getId(), subjectNode);
}
} else {
subjectNode = session.getNode(subjects.getPathFromSubject(subject));
final String path = subjects.getPathFromSubject(subject);
if ( path != null && path.indexOf("%20") != -1 ) {
subjectNode = session.getNode(path.replaceAll("%20"," "));
} else {
subjectNode = session.getNode(path);
}
}

// special logic for handling rdf:type updates.
Expand Down

0 comments on commit 494ab59

Please sign in to comment.