Changeset 8d6a125 for apps/jetty
- Timestamp:
- Dec 19, 2010 12:19:26 AM (10 years ago)
- Branches:
- master
- Children:
- 4622080e
- Parents:
- f8ed3c5
- Location:
- apps/jetty/java/src/org/mortbay/util
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/jetty/java/src/org/mortbay/util/URI.java
rf8ed3c5 r8d6a125 54 54 private UrlEncoded _parameters; 55 55 private boolean _dirty; 56 private static String unreserved = "/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~"; 57 private static String reserved = "!*'();:@&=+$,?%#[]"; 58 private static String hexchars = "0123456789ABCDEF"; 56 59 57 60 /* ------------------------------------------------------------ */ … … 238 241 _parameters.clear(); 239 242 _parameters.decode(_query,__CHARSET); 243 240 244 } 241 245 else … … 567 571 public static StringBuffer encodePath(StringBuffer buf, String path) 568 572 { 569 if (buf==null) 570 { 571 loop: 572 for (int i=0;i<path.length();i++) 573 { 574 char c=path.charAt(i); 575 switch(c) 576 { 577 case '%': 578 case '?': 579 case ';': 580 case '#': 581 case ' ': 582 buf=new StringBuffer(path.length()<<1); 583 break loop; 573 // Convert path to native first. 574 byte[] b = null; 575 /* 576 try { 577 b = path.getBytes(__CHARSET); 578 } catch(UnsupportedEncodingException ex) { 579 return null; // Shouldn't be possible. 580 } 581 */ 582 b = path.getBytes(); 583 StringBuffer x = new StringBuffer(b.length); 584 for(int i=0; i<b.length; i++) { 585 x.append((char)(b[i]&0xff)); 586 } 587 String _path = new String(x); 588 if(buf == null) { 589 loop: 590 for(int i = 0; i < _path.length(); i++) { 591 char c = _path.charAt(i); 592 String cs = "" + c; 593 if(reserved.contains(cs) || !unreserved.contains(cs)) { 594 buf = new StringBuffer(_path.length() << 1); 595 break loop; 584 596 } 585 597 } 586 if (buf==null)598 if(buf == null) { 587 599 return null; 588 } 589 590 synchronized(buf) 591 { 592 for (int i=0;i<path.length();i++) 593 { 594 char c=path.charAt(i); 595 switch(c) 596 { 597 case '%': 598 buf.append("%25"); 599 continue; 600 case '?': 601 buf.append("%3F"); 602 continue; 603 case ';': 604 buf.append("%3B"); 605 continue; 606 case '#': 607 buf.append("%23"); 608 continue; 609 case ' ': 610 buf.append("%20"); 611 continue; 612 default: 613 buf.append(c); 614 continue; 600 } 601 } 602 synchronized(buf) { 603 for(int i = 0; i < _path.length(); i++) { 604 char c = _path.charAt(i); 605 String cs = "" + c; 606 if(reserved.contains(cs) || !unreserved.contains(cs)) { 607 if((c & 0xff) == c) { 608 buf.append(gethex(c & 0xff)); 609 } else { 610 buf.append(gethex((c >> 8) & 0xff)); 611 buf.append(gethex(c & 0xff)); 612 } 613 } else { 614 buf.append(c); 615 615 } 616 616 } … … 620 620 } 621 621 622 /** 623 * 624 * @param decimal value not greater than 255. 625 * @return a percent sign followed by two hexadecimal digits. 626 */ 627 private static String gethex(int decimal) { 628 return new String("%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF)); 629 } 622 630 /* ------------------------------------------------------------ */ 623 631 /** Encode a URI path. … … 709 717 return path; 710 718 719 /* 711 720 try 712 721 { … … 718 727 return new String(bytes,0,n); 719 728 } 729 */ 730 731 return new String(bytes,0,n); 732 720 733 } 721 734
Note: See TracChangeset
for help on using the changeset viewer.