Changeset 56 in code
- Timestamp:
- Nov 29, 2016, 1:52:16 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r53 r56 500 500 } 501 501 502 case html.DoctypeToken, html.CommentToken: 502 case html.CommentToken: 503 // ignore comment. TODO : parse IE conditional comment 504 505 case html.DoctypeToken: 503 506 out.Write(decoder.Raw()) 504 507 } … … 629 632 return "", nil 630 633 } 631 632 634 // TODO check malicious data: - e.g. data:script 633 635 if strings.HasPrefix(uri, "data:") { … … 635 637 } 636 638 637 // parse the uri 639 if len(uri) > 0 && uri[0] == '#' { 640 return uri, nil 641 } 642 638 643 u, err := url.Parse(uri) 639 644 if err != nil { 640 645 return "", err 641 646 } 642 643 // get the fragment (with the prefix "#")644 fragment := ""645 if len(u.Fragment) > 0 {646 fragment = "#" + u.Fragment647 }648 649 // reset the fragment: it is not included in the mortyurl650 u.Fragment = ""651 652 // merge the URI with the document URI653 647 u = mergeURIs(rc.BaseURL, u) 654 648 655 // simple internal link ?656 // some web pages describe the whole link https://same:auth@same.host/same.path?same.query#new.fragment657 if u.Scheme == rc.BaseURL.Scheme &&658 (rc.BaseURL.User == nil || (u.User != nil && u.User.String() == rc.BaseURL.User.String())) &&659 u.Host == rc.BaseURL.Host &&660 u.Path == rc.BaseURL.Path &&661 u.RawQuery == rc.BaseURL.RawQuery {662 // the fragment is the only difference between the document URI and the uri parameter663 return fragment, nil664 }665 666 // return full URI and fragment (if not empty)667 649 uri = u.String() 668 650 669 651 if rc.Key == nil { 670 return fmt.Sprintf("./?mortyurl=%s%s", url.QueryEscape(uri), fragment), nil 671 } 672 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s%s", hash(uri, rc.Key), url.QueryEscape(uri), fragment), 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 656 } 674 657
Note:
See TracChangeset
for help on using the changeset viewer.