- Timestamp:
- Dec 4, 2016, 10:58:41 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r56 r57 632 632 return "", nil 633 633 } 634 634 635 // TODO check malicious data: - e.g. data:script 635 636 if strings.HasPrefix(uri, "data:") { … … 637 638 } 638 639 639 if len(uri) > 0 && uri[0] == '#' { 640 return uri, nil 641 } 642 640 // parse the uri 643 641 u, err := url.Parse(uri) 644 642 if err != nil { 645 643 return "", err 646 644 } 645 646 // get the fragment (with the prefix "#") 647 fragment := "" 648 if len(u.Fragment) > 0 { 649 fragment = "#" + u.Fragment 650 } 651 652 // reset the fragment: it is not included in the mortyurl 653 u.Fragment = "" 654 655 // merge the URI with the document URI 647 656 u = mergeURIs(rc.BaseURL, u) 648 657 658 // simple internal link ? 659 // some web pages describe the whole link https://same:auth@same.host/same.path?same.query#new.fragment 660 if u.Scheme == rc.BaseURL.Scheme && 661 (rc.BaseURL.User == nil || (u.User != nil && u.User.String() == rc.BaseURL.User.String())) && 662 u.Host == rc.BaseURL.Host && 663 u.Path == rc.BaseURL.Path && 664 u.RawQuery == rc.BaseURL.RawQuery { 665 // the fragment is the only difference between the document URI and the uri parameter 666 return fragment, nil 667 } 668 669 // return full URI and fragment (if not empty) 649 670 uri = u.String() 650 671 651 672 if rc.Key == nil { 652 return fmt.Sprintf("./?mortyurl=%s", url.QueryEscape(uri)), nil 653 } 654 655 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s", hash(uri, rc.Key), url.QueryEscape(uri)), nil 673 return fmt.Sprintf("./?mortyurl=%s%s", url.QueryEscape(uri), fragment), nil 674 } 675 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s%s", hash(uri, rc.Key), url.QueryEscape(uri), fragment), nil 656 676 } 657 677
Note:
See TracChangeset
for help on using the changeset viewer.