morten      01/09/21 03:56:10

  Modified:    java/src/org/apache/xalan/xsltc/runtime TextOutput.java
  Log:
  Added a little method to the output post-processor to replace whitespaces
  in URLs by "%20" sequences. This is all the escaping I think we should
  bother our heads doing.
  PR:           bugzilla 1512
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.32      +37 -7     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java
  
  Index: TextOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- TextOutput.java   2001/09/20 14:20:02     1.31
  +++ TextOutput.java   2001/09/21 10:56:09     1.32
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TextOutput.java,v 1.31 2001/09/20 14:20:02 morten Exp $
  + * @(#)$Id: TextOutput.java,v 1.32 2001/09/21 10:56:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -585,6 +585,32 @@
       }
   
       /**
  +     * Replaces whitespaces in a URL with '%20'
  +     */
  +    private String quickAndDirtyUrlEncode(String base) {
  +     final String pst20 = "%20";
  +     final int len = base.length() - 1;
  +     int pos;
  +     // Slow, very slow indeed
  +     while ((pos = base.indexOf(' ')) > -1) {
  +         if (pos == 0) {
  +             final String after = base.substring(1);
  +             base = pst20 + after;
  +         }
  +         else if (pos == len) {
  +             final String before = base.substring(0, pos);
  +             base = before + pst20;
  +         }
  +         else {
  +             final String before = base.substring(0, pos);
  +             final String after = base.substring(pos+1);
  +             base = before + pst20 + after;
  +         }
  +     }
  +     return base;
  +    }
  +
  +    /**
        * Put an attribute and its value in the start tag of an element.
        * Signal an exception if this is attempted done outside a start tag.
        */
  @@ -596,17 +622,21 @@
   
        if (_startTagOpen) {
   
  +         // The following is an attempt to escape an URL stored in a href
  +         // attribute of HTML output. Normally URLs should be encoded at
  +         // the time they are created, since escaping or unescaping a
  +         // completed URI might change its semantics. We limit or escaping
  +         // to include space characters only - and nothing else. This is for
  +         // two reasons: (1) performance and (2) we want to make sure that
  +         // we do not change the meaning of the URL.
  +
            // URL-encode href attributes in HTML output
  -         /* Nope, does not work properly - find other solution
            if (_outputType == HTML) {
                if  (name.toLowerCase().equals("href")) {
  -                 if (value.startsWith("http")) {
  -                     _attributes.add(name, URLEncoder.encode(value));
  -                     return;
  -                 }
  +                 _attributes.add(name, quickAndDirtyUrlEncode(value));
  +                 return;
                }
            }
  -         */
   
            // Intercept namespace declarations and handle them separately
            if (name.startsWith("xml")) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to