Changeset 51 in code for trunk/morty.go
- Timestamp:
- Nov 29, 2016, 10:35:59 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r50 r51 285 285 } 286 286 287 if bytes.Contains(contentType, []byte("xhtml")) { 288 ctx.SetContentType("text/html; charset=UTF-8") 289 } else { 290 ctx.SetContentType(fmt.Sprintf("%s; charset=UTF-8", contentInfo[0])) 291 } 287 ctx.SetContentType(fmt.Sprintf("%s; charset=UTF-8", contentInfo[0])) 292 288 293 289 switch { … … 629 625 return "", nil 630 626 } 627 631 628 // TODO check malicious data: - e.g. data:script 632 629 if strings.HasPrefix(uri, "data:") { … … 634 631 } 635 632 636 if len(uri) > 0 && uri[0] == '#' { 637 return uri, nil 638 } 639 633 // parse the uri 640 634 u, err := url.Parse(uri) 641 635 if err != nil { 642 636 return "", err 643 637 } 638 639 // get the fragment (with the prefix "#") 640 fragment := "" 641 if len(u.Fragment) > 0 { 642 fragment = "#" + u.Fragment 643 } 644 645 // reset the fragment: it is not included in the mortyurl 646 u.Fragment = "" 647 648 // merge the URI with the document URI 644 649 u = mergeURIs(rc.BaseURL, u) 645 650 651 // simple internal link ? 652 // some web pages describe the whole link https://same:auth@same.host/same.path?same.query#new.fragment 653 if u.Scheme == rc.BaseURL.Scheme && 654 ((u.User == nil && rc.BaseURL.User == nil) || (u.User.String() == rc.BaseURL.User.String())) && 655 u.Host == rc.BaseURL.Host && 656 u.Path == rc.BaseURL.Path && 657 u.RawQuery == rc.BaseURL.RawQuery { 658 // the fragment is the only difference between the document URI and the uri parameter 659 return fragment, nil 660 } 661 662 // return full URI and fragment (if not empty) 646 663 uri = u.String() 647 664 648 665 if rc.Key == nil { 649 return fmt.Sprintf("./?mortyurl=%s", url.QueryEscape(uri)), nil 650 } 651 652 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s", hash(uri, rc.Key), url.QueryEscape(uri)), nil 666 return fmt.Sprintf("./?mortyurl=%s%s", url.QueryEscape(uri), fragment), nil 667 } 668 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s%s", hash(uri, rc.Key), url.QueryEscape(uri), fragment), nil 653 669 } 654 670
Note:
See TracChangeset
for help on using the changeset viewer.