···1717 Name string
1818 // Any URL that starts with this value will be rewritten to start, instead, with <base>.
1919 // When more than one insteadOf strings match a given URL, the longest match is used.
2020- InsteadOf string
2020+ InsteadOfs []string
21212222 // raw representation of the subsection, filled by marshal or unmarshal are
2323 // called.
···26262727// Validate validates fields of branch
2828func (b *URL) Validate() error {
2929- if b.InsteadOf == "" {
2929+ if len(b.InsteadOfs) == 0 {
3030 return errURLEmptyInsteadOf
3131 }
3232···4141 u.raw = s
42424343 u.Name = s.Name
4444- u.InsteadOf = u.raw.Option(insteadOfKey)
4444+ u.InsteadOfs = u.raw.OptionAll(insteadOfKey)
4545 return nil
4646}
4747···5151 }
52525353 u.raw.Name = u.Name
5454- u.raw.SetOption(insteadOfKey, u.InsteadOf)
5454+ u.raw.SetOption(insteadOfKey, u.InsteadOfs...)
55555656 return u.raw
5757}
58585959func findLongestInsteadOfMatch(remoteURL string, urls map[string]*URL) *URL {
6060 var longestMatch *URL
6161+ var longestMatchLength int
6262+6163 for _, u := range urls {
6262- if !strings.HasPrefix(remoteURL, u.InsteadOf) {
6363- continue
6464- }
6464+ for _, currentInsteadOf := range u.InsteadOfs {
6565+ if !strings.HasPrefix(remoteURL, currentInsteadOf) {
6666+ continue
6767+ }
6868+6969+ lengthCurrentInsteadOf := len(currentInsteadOf)
65706666- // according to spec if there is more than one match, take the logest
6767- if longestMatch == nil || len(longestMatch.InsteadOf) < len(u.InsteadOf) {
6868- longestMatch = u
7171+ // according to spec if there is more than one match, take the longest
7272+ if longestMatch == nil || longestMatchLength < lengthCurrentInsteadOf {
7373+ longestMatch = u
7474+ longestMatchLength = lengthCurrentInsteadOf
7575+ }
6976 }
7077 }
7178···7380}
74817582func (u *URL) ApplyInsteadOf(url string) string {
7676- if !strings.HasPrefix(url, u.InsteadOf) {
7777- return url
8383+ for _, j := range u.InsteadOfs {
8484+ if strings.HasPrefix(url, j) {
8585+ return u.Name + url[len(j):]
8686+ }
7887 }
79888080- return u.Name + url[len(u.InsteadOf):]
8989+ return url
8190}