LEFT | RIGHT |
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 != "" { | 462 » » if u.Path != "" && u.Path[0] != '/' { |
463 » » » if u.Path[0] != '/' { | 463 » » » buf.WriteByte('/') |
464 » » » » buf.WriteByte('/') | |
465 » » » } | |
466 } | 464 } |
467 buf.WriteString(escape(u.Path, encodePath)) | 465 buf.WriteString(escape(u.Path, encodePath)) |
468 } | 466 } |
469 if u.RawQuery != "" { | 467 if u.RawQuery != "" { |
470 buf.WriteByte('?') | 468 buf.WriteByte('?') |
471 buf.WriteString(u.RawQuery) | 469 buf.WriteString(u.RawQuery) |
472 } | 470 } |
473 if u.Fragment != "" { | 471 if u.Fragment != "" { |
474 buf.WriteByte('#') | 472 buf.WriteByte('#') |
475 buf.WriteString(escape(u.Fragment, encodeFragment)) | 473 buf.WriteString(escape(u.Fragment, encodeFragment)) |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } else { | 691 } else { |
694 if strings.HasPrefix(result, "//") { | 692 if strings.HasPrefix(result, "//") { |
695 result = u.Scheme + ":" + result | 693 result = u.Scheme + ":" + result |
696 } | 694 } |
697 } | 695 } |
698 if u.RawQuery != "" { | 696 if u.RawQuery != "" { |
699 result += "?" + u.RawQuery | 697 result += "?" + u.RawQuery |
700 } | 698 } |
701 return result | 699 return result |
702 } | 700 } |
LEFT | RIGHT |