Skip to content

Commit

Permalink
Bug 509028: Encode path to avoid URISyntaxException
Browse files Browse the repository at this point in the history
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=509028
Change-Id: If5f63ac719b202abc480e1770525b101cef0057d
Signed-off-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
  • Loading branch information
guw committed Dec 11, 2016
1 parent e728293 commit 3bbda48
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/*******************************************************************************
* Copyright (c) 2011 SAP AG and others.
* Copyright (c) 2011, 2016 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP AG - initial API and implementation
* Gunnar Wagenknecht (Salesforce) - fix for bug 509028
*******************************************************************************/
package org.eclipse.tycho.repository.registry.facade;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;

public class RepositoryBlackboardKey {

// TODO p2 bug 347319 prevents using a special scheme, that will ensure that only our p2 repository factory load the blackboard key URIs
// TODO p2 bug 347319 prevents using a special scheme, that will ensure that only our p2 repository factory load the blackboard key URIs
//public static String SCHEME = "registry";
public static final String SCHEME = "file";

Expand All @@ -36,10 +39,14 @@ public URI toURI() {
*/
public static RepositoryBlackboardKey forResolutionContextArtifacts(File projectLocation) {
try {
return new RepositoryBlackboardKey(
new URI(SCHEME, "/resolution-context-artifacts@" + projectLocation, null));
return new RepositoryBlackboardKey(new URI(SCHEME,
"/resolution-context-artifacts@" + URLEncoder.encode(String.valueOf(projectLocation), "UTF-8"),
null));
} catch (URISyntaxException e) {
// the used constructor escapes invalid characters, so I don't see this happening
// the used constructor does not escape invalid characters but we encode, so I don't see this happening (bug 509028)
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
// UTF-8 should be supported on any JVM
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 3bbda48

Please sign in to comment.