Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344760

Summary: URIUtil#append Can't handle files with square brackets in the name
Product: [Eclipse Project] Equinox Reporter: John Arthorne <john.arthorne>
Component: ComponentsAssignee: John Arthorne <john.arthorne>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: tjwatson
Version: 3.7Flags: tjwatson: review+
Target Milestone: 3.7 RC1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Fix none

Description John Arthorne CLA 2011-05-04 16:03:20 EDT
0.2 M7

If you create a project containing files with square brackets in the name, you get:

java.lang.RuntimeException: java.net.URISyntaxException: Illegal character in path at index 17: director%20app%20[john].launch
	at org.eclipse.core.runtime.URIUtil.append(URIUtil.java:82) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.DirectoryHandlerV1.encodeChildren(DirectoryHandlerV1.java:71) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.DirectoryHandlerV1.handleGet(DirectoryHandlerV1.java:56) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.DirectoryHandlerV1.handleRequest(DirectoryHandlerV1.java:248) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.DirectoryHandlerV1.handleRequest(DirectoryHandlerV1.java:1) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.ServletFileStoreHandler.handleDirectory(ServletFileStoreHandler.java:128) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.ServletFileStoreHandler.handleRequest(ServletFileStoreHandler.java:148) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.ServletFileStoreHandler.handleRequest(ServletFileStoreHandler.java:1) ~[na:na]
	at org.eclipse.orion.internal.server.servlets.file.NewFileServlet.doGet(NewFileServlet.java:56) ~[na:na]
Comment 1 John Arthorne CLA 2011-05-06 13:45:54 EDT
This is a bug in URIUtil. It's a friend of bug 331314.
Comment 2 John Arthorne CLA 2011-05-06 13:48:00 EDT
Created attachment 194965 [details]
Fix

The fix is quite simple, just like bug 331314. Since append has different code paths depending on whether the base URI has a trailing slash, I tested all combinations in the regression test. In fact it is on the trailing slash case that currently fails.
Comment 3 Thomas Watson CLA 2011-05-06 15:09:19 EDT
+1 to the fix.

I think there is a similar issue for opaque URIs but I could not seem to find a good solution.  Here is my testcase:

URI opaque = new URI("opaque:something/opaque/");
result = URIUtil.append(opaque, "some/path/file[with brackets].txt");

assertEquals(
             "5.0", 
             "opaque:something/opaque/some/path/file%5Bwith%20brackets%5D.txt", 
             result.toString()
);
assertEquals("5.1", null, result.getPath());


Perhaps I have a misunderstanding for opaque URIs.
Comment 4 John Arthorne CLA 2011-05-06 15:35:43 EDT
Yeah it's kind of bogus that we allow appending opaque URI's at all. Technically they have no path. However we do it to handle malformed file URI's such as:

file:C:/some/path/f.txt

I'm ok with leaving that case broken... the client should really be fixing their code to avoid using opaque URIs if they are appending path segments.
Comment 5 John Arthorne CLA 2011-05-06 15:44:29 EDT
Fix released.