Bug 53359 - Request for <Aliases> or <Alias> as element inside <Context>
Summary: Request for <Aliases> or <Alias> as element inside <Context>
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.27
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-05 00:35 UTC by Esmond Pitt
Modified: 2012-06-06 20:02 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Esmond Pitt 2012-06-05 00:35:47 UTC
I have a large and growing number of requirements for aliases, and the existing (new for Tomcat 7) aliases= attribute is unwieldy for me. The line is already 289 characters long ;-(
 
It would be a lot more convenient if aliases could be specified individually via a repeatable nested <Alias> entry, something like:
 
<Context>
<Alias aliasPath="/xyz" docBase="/real_path"/> ...
</Context>

as opposed to current:

<Context
	path="/cLabs"
	crossContext="true"
	aliases="/EDSILabCatalog=c:/xampp/htdocs/cLabs/EDSILabCatalog,/EDSILabs=c:/xampp/htdocs/cLabs/EDSILabs,/Global=c:/xampp/htdocs/cLabs/Global,/Skyline=c:/xampp/htdocs/cLabs/Skyline,/Sun=c:/xampp/htdocs/cLabs/Sun,/Sunset=c:/xampp/htdocs/cLabs/Sunset,/Tech2000=c:/xampp/htdocs/cLabs/Tech2000"
	/>
Comment 1 Mark Thomas 2012-06-05 18:26:30 UTC
I'd rather avoid adding that option since it adds complexity to the code I'd rather not have. What if we ensured that white-space was trimmed so you could use something like:
aliases="/pathA=C:/pathA,
         /pathB=C:/some/other/path,
         /special=C:/here/be/dragons"

Thoughts?
Comment 2 Esmond Pitt 2012-06-06 00:04:22 UTC
That's OK by me but is it legal XML?
Comment 3 Christopher Schultz 2012-06-06 01:20:02 UTC
There is no prohibition of any kind of whitespace (except maybe form-feed?) in an attribute value. You only need to escape the standard < and > plus " characters.
Comment 4 Esmond Pitt 2012-06-06 05:02:12 UTC
In that case Mark Thomas's solution is perfect. I would have thought you needed to trim the whitespace anyway, to allow spaces after the commas as per many programming habits ;-)
Comment 5 Christopher Schultz 2012-06-06 17:49:00 UTC
I'm prepared to make this fix, but I want to be sure I can do it all in one place. Mark, could you comment?

It looks like BaseDirContext.java:237 could just change from

        String[] kvps = theAliases.split(",");

to

        String[] kvps = theAliases.split("\\s*,\\s*");

I've read-through the rest of the code and it appears that this is all that is required, but there may be other places where similar splits are happening.
Comment 6 Mark Thomas 2012-06-06 18:09:37 UTC
That is the only place this gets processed but you'll need to do the same with the split("=") two lines as well for completeness.

A test case would be nice too as would an update to the docs on hoe white space will be handled :)
Comment 7 Konstantin Kolinko 2012-06-06 18:13:02 UTC
I think you should also beware of empty strings (produced by ',,' or by an extra ',' at the end of values) and ignore them.
Comment 8 Christopher Schultz 2012-06-06 18:21:12 UTC
(In reply to comment #6)
> That is the only place this gets processed but you'll need to do the same
> with the split("=") two lines as well for completeness.

I'm happy to do that, but didn't want the patch to grow bigger than the original requirements. It makes perfect sense to me to trim whitespace around the '='.

> A test case would be nice too as would an update to the docs on hoe white
> space will be handled :)

Of course. I mainly wanted to verify that this was the only place a functional change needed to be made.

(In reply to comment #7)
> I think you should also beware of empty strings (produced by ',,' or by an
> extra ',' at the end of values) and ignore them.

Noted.
Comment 9 Christopher Schultz 2012-06-06 19:46:41 UTC
Looks like I can't avoid using String.trim() anyway, so I'm just going to use that instead of modifying the regex.
Comment 10 Christopher Schultz 2012-06-06 19:57:27 UTC
Okay, I'm going to close this as WONTFIX and create a new bug for trimming whitespace. I'm doing this so that this bug can be REOPENED in the future if there is sufficient demand for <Alias> subelements within <Context>.
Comment 11 Christopher Schultz 2012-06-06 20:02:02 UTC
Replacement is bug 53373.