Bug 22860 - tag url generate invalid result for root context
Summary: tag url generate invalid result for root context
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: unspecified
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-01 14:36 UTC by Cyril Sochor
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cyril Sochor 2003-09-01 14:36:05 UTC
Tag URL is buggy for context "/".

<c:url context="/" value="/something.jsp"/>
produce
"//something.jsp"
this is interpreted by browser (Galleion 1.3.5) as host name, not as absolute path .

Correct result is "/something.jsp"
Comment 1 Pierre Delisle 2003-09-10 20:33:41 UTC
Hummm,
The 'context' attribute is to be used to specify
a *foreign* context.

From the spec:
  Name of the context when specifying a relative URL
  resource that belongs to a foreign context.

Specifying '/' does not represent a valid foreign context,
and therefore leads to the problem you're having.

If a resource belongs to the current context, attribute
context should not be used.
Comment 2 Cyril Sochor 2003-09-17 12:17:50 UTC
I hope that '/' is valid foreign context, if context-root element in
application.xml is '/'.
For example, this is my application.xml:
<application>
  <module>
    <web>
	<web-uri>hyperion-frontend.war</web-uri>
	<context-root>/</context-root>
    </web>
  </module>
    <web>
	<web-uri>hyperion-backend.war</web-uri>
	<context-root>hyperion-admin</context-root>
    </web>
  </module>
</application>

I need generate link from backend application to frontend application.
Applications have diferent contex, attribute 'context' of tag 'c:url' must be
supplied
There is some.jsp in hyperion-backand.war with this tag:
<c:url var="frontendLinkURL" value="/main.jsp" context="/"/>
It generate <a href="//main.jsp"/> :-(

It's bad result, because many browsers interpret this as host name, not
as absolute path at same host. Correct result is <a href="/main.jsp"/>

There is my patch:

Index: UrlSupport.java
===================================================================
RCS file:
/home/cvspublic/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/UrlSupport.java,v
retrieving revision 1.6
diff -u -r1.6 UrlSupport.java
--- UrlSupport.java     4 Aug 2003 17:44:37 -0000       1.6
+++ UrlSupport.java     2 Sep 2003 13:51:17 -0000
@@ -189,7 +189,12 @@
             if (!context.startsWith("/") || !url.startsWith("/"))
                 throw new JspTagException(
                     Resources.getMessage("IMPORT_BAD_RELATIVE"));
-            return (context + url);
+            if (context.equals("/")) {
+               // don't produce string starting with "//", many
browsers
interpreting this url as host name, not as absolute path on same host
+                               return url;
+            } else {
+                               return (context + url);
+            }
         }
     }

Comment 3 Pierre Delisle 2003-12-12 23:39:06 UTC
My bad, apologies... Just committed the fix for JSTL 1.1.
Thanks for the bug report Cyril.