Changeset 56 in code for trunk/morty.go


Ignore:
Timestamp:
Nov 29, 2016, 1:52:16 PM (9 years ago)
Author:
alex
Message:

[fix] ignore all comments (quick fix about the privacy issue with IE conditional comments)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r53 r56  
    500500                                }
    501501
    502                         case html.DoctypeToken, html.CommentToken:
     502                        case html.CommentToken:
     503                                // ignore comment. TODO : parse IE conditional comment
     504
     505                        case html.DoctypeToken:
    503506                                out.Write(decoder.Raw())
    504507                        }
     
    629632                return "", nil
    630633        }
    631 
    632634        // TODO check malicious data: - e.g. data:script
    633635        if strings.HasPrefix(uri, "data:") {
     
    635637        }
    636638
    637         // parse the uri
     639        if len(uri) > 0 && uri[0] == '#' {
     640                return uri, nil
     641        }
     642
    638643        u, err := url.Parse(uri)
    639644        if err != nil {
    640645                return "", err
    641646        }
    642 
    643         // get the fragment (with the prefix "#")
    644         fragment := ""
    645         if len(u.Fragment) > 0 {
    646                 fragment = "#" + u.Fragment
    647         }
    648 
    649         // reset the fragment: it is not included in the mortyurl
    650         u.Fragment = ""
    651 
    652         // merge the URI with the document URI
    653647        u = mergeURIs(rc.BaseURL, u)
    654648
    655         // simple internal link ?
    656         // some web pages describe the whole link https://same:auth@same.host/same.path?same.query#new.fragment
    657         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 parameter
    663                 return fragment, nil
    664         }
    665 
    666         // return full URI and fragment (if not empty)
    667649        uri = u.String()
    668650
    669651        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
    673656}
    674657
Note: See TracChangeset for help on using the changeset viewer.