OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package url parses URLs and implements query escaping. | 5 // Package url parses URLs and implements query escaping. |
6 // See RFC 3986. | 6 // See RFC 3986. |
7 package url | 7 package url |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 if u.Scheme != "" || u.Host != "" || u.User != nil { | 452 if u.Scheme != "" || u.Host != "" || u.User != nil { |
453 buf.WriteString("//") | 453 buf.WriteString("//") |
454 if u := u.User; u != nil { | 454 if u := u.User; u != nil { |
455 buf.WriteString(u.String()) | 455 buf.WriteString(u.String()) |
456 buf.WriteByte('@') | 456 buf.WriteByte('@') |
457 } | 457 } |
458 if h := u.Host; h != "" { | 458 if h := u.Host; h != "" { |
459 buf.WriteString(h) | 459 buf.WriteString(h) |
460 } | 460 } |
461 } | 461 } |
| 462 if u.Path != "" { |
| 463 if u.Path[0] != '/' { |
| 464 buf.WriteByte('/') |
| 465 } |
| 466 } |
462 buf.WriteString(escape(u.Path, encodePath)) | 467 buf.WriteString(escape(u.Path, encodePath)) |
463 } | 468 } |
464 if u.RawQuery != "" { | 469 if u.RawQuery != "" { |
465 buf.WriteByte('?') | 470 buf.WriteByte('?') |
466 buf.WriteString(u.RawQuery) | 471 buf.WriteString(u.RawQuery) |
467 } | 472 } |
468 if u.Fragment != "" { | 473 if u.Fragment != "" { |
469 buf.WriteByte('#') | 474 buf.WriteByte('#') |
470 buf.WriteString(escape(u.Fragment, encodeFragment)) | 475 buf.WriteString(escape(u.Fragment, encodeFragment)) |
471 } | 476 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 } else { | 693 } else { |
689 if strings.HasPrefix(result, "//") { | 694 if strings.HasPrefix(result, "//") { |
690 result = u.Scheme + ":" + result | 695 result = u.Scheme + ":" + result |
691 } | 696 } |
692 } | 697 } |
693 if u.RawQuery != "" { | 698 if u.RawQuery != "" { |
694 result += "?" + u.RawQuery | 699 result += "?" + u.RawQuery |
695 } | 700 } |
696 return result | 701 return result |
697 } | 702 } |
OLD | NEW |