Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1156)

Delta Between Two Patch Sets: src/pkg/net/url/url.go

Issue 11698045: code review 11698045: net/url: prepend slash to path in String() (Closed)
Left Patch Set: diff -r 86a2e482982f https://code.google.com/p/go Created 10 years, 8 months ago
Right Patch Set: diff -r 86a2e482982f https://code.google.com/p/go Created 10 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/net/url/url_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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('/')
0xjnml 2013/07/24 07:49:04 You can save two lines by: if u.Path != "" && u.P
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b