fix encoding and decoding for branches including slashes

This commit is contained in:
Eduard Heimbuch
2019-11-01 13:52:53 +01:00
parent 557856185a
commit d5bd83fafb
3 changed files with 12 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ class Sources extends React.Component<Props, State> {
const { fetchBranches, repository, revision, path, fetchSources } = this.props; const { fetchBranches, repository, revision, path, fetchSources } = this.props;
fetchBranches(repository); fetchBranches(repository);
fetchSources(repository, revision, path); fetchSources(repository, this.decodeRevision(revision), path);
this.redirectToDefaultBranch(); this.redirectToDefaultBranch();
} }
@@ -61,12 +61,16 @@ class Sources extends React.Component<Props, State> {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const { fetchSources, repository, revision, path } = this.props; const { fetchSources, repository, revision, path } = this.props;
if (prevProps.revision !== revision || prevProps.path !== path) { if (prevProps.revision !== revision || prevProps.path !== path) {
fetchSources(repository, revision, path); fetchSources(repository, this.decodeRevision(revision), path);
} }
this.redirectToDefaultBranch(); this.redirectToDefaultBranch();
} }
decodeRevision = (revision: string) => {
return revision ? decodeURIComponent(revision) : revision;
};
redirectToDefaultBranch = () => { redirectToDefaultBranch = () => {
const { branches } = this.props; const { branches } = this.props;
if (this.shouldRedirectToDefaultBranch()) { if (this.shouldRedirectToDefaultBranch()) {
@@ -171,7 +175,7 @@ class Sources extends React.Component<Props, State> {
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {
const { repository, match } = ownProps; const { repository, match } = ownProps;
const { revision, path } = match.params; const { revision, path } = match.params;
const decodedRevision = revision ? decodeURIComponent(revision) : revision; const decodedRevision = revision ? decodeURIComponent(revision) : undefined;
const loading = isFetchBranchesPending(state, repository); const loading = isFetchBranchesPending(state, repository);
const error = getFetchBranchesFailure(state, repository); const error = getFetchBranchesFailure(state, repository);
const branches = getBranches(state, repository); const branches = getBranches(state, repository);
@@ -198,7 +202,7 @@ const mapDispatchToProps = dispatch => {
dispatch(fetchBranches(repository)); dispatch(fetchBranches(repository));
}, },
fetchSources: (repository: Repository, revision: string, path: string) => { fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, decodeURIComponent(revision), path)); dispatch(fetchSources(repository, revision, path));
} }
}; };
}; };

View File

@@ -16,10 +16,10 @@ export function fetchSources(repository: Repository, revision: string, path: str
.get(createUrl(repository, revision, path)) .get(createUrl(repository, revision, path))
.then(response => response.json()) .then(response => response.json())
.then(sources => { .then(sources => {
dispatch(fetchSourcesSuccess(repository, decodeURIComponent(revision), path, sources)); dispatch(fetchSourcesSuccess(repository, revision, path, sources));
}) })
.catch(err => { .catch(err => {
dispatch(fetchSourcesFailure(repository, decodeURIComponent(revision), path, err)); dispatch(fetchSourcesFailure(repository, revision, path, err));
}); });
}; };
} }

View File

@@ -14,6 +14,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.net.URLDecoder;
import static sonia.scm.ContextEntry.ContextBuilder.entity; import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound; import static sonia.scm.NotFoundException.notFound;
@@ -57,7 +58,7 @@ public class SourceRootResource {
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand(); BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
browseCommand.setPath(path); browseCommand.setPath(path);
if (revision != null && !revision.isEmpty()) { if (revision != null && !revision.isEmpty()) {
browseCommand.setRevision(revision); browseCommand.setRevision(URLDecoder.decode(revision, "UTF-8"));
} }
browseCommand.setDisableCache(true); browseCommand.setDisableCache(true);
BrowserResult browserResult = browseCommand.getBrowserResult(); BrowserResult browserResult = browseCommand.getBrowserResult();