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